From b39aeeceff7993ad9c98c7d3c8b326ee1e67c081 Mon Sep 17 00:00:00 2001 From: Kimi Heinonen <kimiheinonen@hotmail.com> Date: Sat, 2 Mar 2019 20:27:40 +0200 Subject: [PATCH] Implementoitu tyhjat metodit --- Assets/Scripts/City.cs | 49 +++++++++++++++++++++++++++++++--- Assets/Scripts/ResourcePool.cs | 5 +--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/City.cs b/Assets/Scripts/City.cs index 5c15fd4..f0a557f 100644 --- a/Assets/Scripts/City.cs +++ b/Assets/Scripts/City.cs @@ -5,7 +5,24 @@ using UnityEngine; public class City : MonoBehaviour { - + [SerializeField] + GameObject worker; + + [SerializeField] + public int population = 0; + + [SerializeField] + public int populationLevel = 0; + + [SerializeField] + public int resourcePoolLevel = 0; + + [SerializeField] + public int roadLevel = 0; + + [SerializeField] + public int collectorLevel = 0; + // Start is called before the first frame update void Start() @@ -15,12 +32,30 @@ public class City : MonoBehaviour public int GetLevel(UpgradeTargets target) { + switch (target) + { + case UpgradeTargets.population: + return this.populationLevel; + case UpgradeTargets.capacity: + return this.resourcePoolLevel; + case UpgradeTargets.speed: + return this.roadLevel; + case UpgradeTargets.collector: + return this.collectorLevel; + default: + Debug.Log("Default"); + return -1; + break; + } return 1; } public void AddCollector() { - + + GameObject go = Instantiate<GameObject>(worker); + + go.transform.position = new Vector3(); } @@ -46,7 +81,7 @@ public class City : MonoBehaviour public void AddPopulation(int v) { - + this.population += v; } @@ -87,9 +122,15 @@ public class City : MonoBehaviour { lista[i].SetCapacity(x); } + this.resourcePoolLevel++; } public void UseResources(List<int> a) { - + ResourcePool[] lista = gameObject.GetComponents<ResourcePool>(); + + for (int i = 0; i < lista.Length; i++) + { + UseResource(lista[i].GetResource(), a[0]); + } } } diff --git a/Assets/Scripts/ResourcePool.cs b/Assets/Scripts/ResourcePool.cs index c4cbf61..95dc991 100644 --- a/Assets/Scripts/ResourcePool.cs +++ b/Assets/Scripts/ResourcePool.cs @@ -59,8 +59,5 @@ public class ResourcePool : MonoBehaviour { this.maxCapacity += x; } - public void AddCollector() - { - Collector c = gameObject.AddComponent<Collector>(); - } + } -- GitLab