46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using Framework.Manager;
|
|
using Gameplay.Manager;
|
|
using UnityEngine;
|
|
using PhxhSDK;
|
|
|
|
namespace Gameplay.Level
|
|
{
|
|
public class DestroyPlank : MonoBehaviour
|
|
{
|
|
private GameObject _gfxFirework;
|
|
|
|
private ParticleSystem _particleSystem;
|
|
|
|
private float _limitPosX;
|
|
|
|
private void Awake()
|
|
{
|
|
var mainCamera = CameraManager.Instance.MainCamera;
|
|
var worldWidth = mainCamera.ScreenToWorldPoint(new Vector3(Screen.width, 0f, 0f)).x -
|
|
mainCamera.ScreenToWorldPoint(Vector3.zero).x;
|
|
|
|
_limitPosX = worldWidth / 2;
|
|
_gfxFirework = gameObject.transform.Find("gfx_plank_firework").gameObject;
|
|
_particleSystem = _gfxFirework.GetComponent<ParticleSystem>();
|
|
}
|
|
|
|
private void OnCollisionEnter2D(Collision2D collision)
|
|
{
|
|
LevelManager.Instance.CachePlank(collision.gameObject.name);
|
|
|
|
var plank = collision.gameObject;
|
|
var plankPosX = plank.transform.position.x;
|
|
var realX = plankPosX > -_limitPosX && plankPosX < _limitPosX ? plankPosX :
|
|
plankPosX > 0 ? _limitPosX : -_limitPosX;
|
|
|
|
var oldGfxPos = _gfxFirework.transform.position;
|
|
var newGfxPos = new Vector3(realX, oldGfxPos.y, oldGfxPos.z);
|
|
_gfxFirework.transform.position = newGfxPos;
|
|
|
|
_gfxFirework.gameObject.SetActive(true);
|
|
GfxManager.Instance.ShowGfxOnce(_particleSystem, _gfxFirework);
|
|
AudioManager.Instance.PlaySound(AudioType.SOUND, "S_PlankDrop", new UnityAudio(false));
|
|
}
|
|
|
|
}
|
|
} |