From e2df2c4332326bfaf1da9f03ba6c51ff4c1ad0a7 Mon Sep 17 00:00:00 2001
From: Anna Matela <N2970@student.jamk.fi>
Date: Tue, 2 Mar 2021 15:37:41 +0200
Subject: [PATCH] more tweeks to bomb explosion animation

---
 .../Assets/Scripts/BombCollectible.cs         | 19 +++++++++++--------
 .../Assets/Scripts/PlayerController.cs        |  3 ++-
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/2D Winter Adventure/Assets/Scripts/BombCollectible.cs b/2D Winter Adventure/Assets/Scripts/BombCollectible.cs
index 3944778..0fddb09 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 40420b9..8bc1d23 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()
-- 
GitLab