Updated collapsing platform script
This commit is contained in:
@@ -1,9 +1,51 @@
|
||||
using System.Collections;
|
||||
using Movement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Platforms
|
||||
{
|
||||
public class CollapsingPlatform : MonoBehaviour
|
||||
{
|
||||
|
||||
private const float TimeBeforeCollapse = 2.0f;
|
||||
private const float TimeBeforeReset = 4.0f;
|
||||
|
||||
private CollisionChecker _collidingTriggerCheck;
|
||||
|
||||
private bool _onCollision;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_collidingTriggerCheck = GetComponentInChildren<CollisionChecker>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_collidingTriggerCheck.IsCollided || _onCollision) return;
|
||||
Debug.Log("On collision");
|
||||
_onCollision = true;
|
||||
StartCoroutine(Collapse());
|
||||
}
|
||||
|
||||
private void ChangeState(bool state)
|
||||
{
|
||||
GetComponent<SpriteRenderer>().enabled = state;
|
||||
GetComponent<Collider2D>().enabled = state;
|
||||
}
|
||||
|
||||
private IEnumerator Collapse()
|
||||
{
|
||||
//changer sprite en rouge
|
||||
yield return new WaitForSeconds(TimeBeforeCollapse);
|
||||
ChangeState(false);
|
||||
StartCoroutine(Reset());
|
||||
}
|
||||
|
||||
private IEnumerator Reset()
|
||||
{
|
||||
yield return new WaitForSeconds(TimeBeforeReset);
|
||||
_onCollision = false;
|
||||
//change sprite en normal
|
||||
ChangeState(true);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user