From a5cd597a2e9562b0422cc9c27012bae7be9c204a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Leevi=20Gr=C3=B6nlund?= <lejugr@utu.fi>
Date: Sat, 2 Mar 2019 16:38:01 +0200
Subject: [PATCH] Resources some updates.

---
 Assets/Scripts/Forest.cs   | 9 ++++-----
 Assets/Scripts/Resource.cs | 9 ++++++++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Assets/Scripts/Forest.cs b/Assets/Scripts/Forest.cs
index 2900ac7..cc8347e 100644
--- a/Assets/Scripts/Forest.cs
+++ b/Assets/Scripts/Forest.cs
@@ -20,7 +20,7 @@ public class Forest : Resource
         }
     }
 
-    public void refreshSprite()
+    public override void refreshSprite()
     {
         if (resources < 125)
         {
@@ -70,22 +70,21 @@ public class Forest : Resource
         resources = Random.Range(50, 300);
         isForester = false;
         growthspeed = 1;
+        StartCoroutine("Grow");
     }
 
     // Update is called once per frame
     void Update()
     {
-        checkExistence();
-        StartCoroutine("Grow");
-        refreshSprite();
+        
     }
 
     IEnumerator Grow()
     {
-        yield return new WaitForSeconds(growthspeed);
         while (resources < 1000)
         {
             resources++;
+            yield return new WaitForSeconds(growthspeed);
         }
     }
 }
diff --git a/Assets/Scripts/Resource.cs b/Assets/Scripts/Resource.cs
index 0d34126..12e2222 100644
--- a/Assets/Scripts/Resource.cs
+++ b/Assets/Scripts/Resource.cs
@@ -24,17 +24,24 @@ public abstract class Resource : MonoBehaviour
         {
             int r = resources;
             resources = 0;
+            refreshSprite();
+            checkExistence();
             return r;
         }
         else
         {
             resources = resources - amount;
+            refreshSprite();
+            checkExistence();
             return amount;
         }
       
     }
 
+    public abstract void refreshSprite();
+
+
+
 
-    
     public abstract void checkExistence();
 }
-- 
GitLab