52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
|
|
using RR.Common.Managers;
|
|
using RR.Game2D.Behaviour;
|
|
using RR.Game2D.Entities;
|
|
using RR.Game2D.Core.Managers;
|
|
|
|
namespace RR.Game2D.FX
|
|
{
|
|
[RequireComponent(typeof(VisualEffect))]
|
|
public class CheckPointFX : MonoBehaviour
|
|
{
|
|
[SerializeField] private VisualEffect checkPointVFX;
|
|
[SerializeField] private SoundEffect checkpointSFX;
|
|
// [SerializeField] private Vector2 offset = Vector2.zero;
|
|
//[SerializeField] private Color color = Color.white;
|
|
|
|
private GameObject _player;
|
|
private Rigidbody2D _playerRB;
|
|
private PlayerController _playerController;
|
|
|
|
private void OnDestroy()
|
|
{
|
|
CheckpointSystem.Instance.ActiveChanged -= PlayFX;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_player = GameManager.Instance.PlayerObj;
|
|
|
|
if (_player == null) _player = GameObject.FindGameObjectWithTag("Player");
|
|
|
|
_playerRB = _player.GetComponent<Rigidbody2D>();
|
|
_playerController = _player.GetComponent<PlayerController>();
|
|
|
|
checkPointVFX.Stop();
|
|
|
|
CheckpointSystem.Instance.ActiveChanged += PlayFX;
|
|
}
|
|
|
|
private void PlayFX(Checkpoint previous,Checkpoint current)
|
|
{
|
|
transform.position = current.transform.position;
|
|
transform.rotation = current.transform.rotation;
|
|
checkPointVFX.Play();
|
|
GameManager.Instance.Audio.PlaySfxAt(checkpointSFX.sound, transform.position,
|
|
checkpointSFX.volume, checkpointSFX.pitch);
|
|
checkPointVFX.Stop();
|
|
}
|
|
}
|
|
} |