diff --git a/2D Winter Adventure/Assets/Scripts/BombCollectible.cs b/2D Winter Adventure/Assets/Scripts/BombCollectible.cs index 394477848106939944b363781a1683bfde02f3fe..0fddb0986cc98d325fe3932aa483496b2b3eb12a 100644 --- a/2D Winter Adventure/Assets/Scripts/BombCollectible.cs +++ b/2D Winter Adventure/Assets/Scripts/BombCollectible.cs @@ -8,29 +8,32 @@ public class BombCollectible : MonoBehaviour { public bool isExploded = false; Animator animator; - PlayerController controller; + PlayerController controller; - private void OnTriggerEnter2D(Collider2D other) + void Start() { animator = GetComponent<Animator>(); + } + + private void OnTriggerEnter2D(Collider2D other) + { controller = other.GetComponent<PlayerController>(); if (controller != null && isExploded == false) { isExploded = true; animator.SetBool("isExploded", true); - - StartCoroutine(waiter()); - + Invoke("Explode", 1f); + } } - IEnumerator waiter() + void Explode() { - yield return new WaitForSeconds(1); controller.ChangeHealth(-1); - Destroy(gameObject); + gameObject.SetActive(false); } + } // https://stackoverflow.com/questions/30056471/how-to-make-the-script-wait-sleep-in-a-simple-way-in-unity diff --git a/2D Winter Adventure/Assets/Scripts/PlayerController.cs b/2D Winter Adventure/Assets/Scripts/PlayerController.cs index 40420b9724601606a1c042c19889d1494347408c..8bc1d239c8908369a70e606fb52d2ee1a1c5c916 100644 --- a/2D Winter Adventure/Assets/Scripts/PlayerController.cs +++ b/2D Winter Adventure/Assets/Scripts/PlayerController.cs @@ -44,7 +44,8 @@ public class PlayerController : MonoBehaviour void Start() { controller = gameObject.GetComponent<PlayerController>(); - currentHealth = 3; + animator = GetComponent<Animator>(); + currentHealth = maxHealth; } private void Awake()