Hey! So I am trying to implement a Money System where the buildings cost money to place and houses generate income and towers take income but there is a error for trying to make houses cost money. Here is the problem
[LIST=1]
[*] ScoreManager sm = GameObject.FindObjectOfType<ScoreManager> ();
[*] if(sm.money < bm.SelectedBuilding.GetComponent<house>().cost) {
[*] return;
[*] }
[/LIST]
Im not sure what the problem is and if somebody could help it would be great (Everything after and including GetComponent is red)
Here is my whole script.
[LIST=1]
[*]using UnityEngine;
[*]using UnityEngine.UI;
[*]public class GUIScript : MonoBehaviour {
[*] BuildManager bm;
[*] Button house, tower, path, field;
[*] bool buildopen = false;
[*] // Use this for initialization
[*] void Start () {
[*] bm = GameObject.Find("BuildManager").GetComponent<BuildManager>();
[*] Canvas cv = GameObject.Find("Canvas").GetComponent<Canvas>();
[*] house = cv.transform.FindChild("HouseButton").gameObject.GetComponent<Button>();
[*] tower = cv.transform.FindChild("TowerButton").gameObject.GetComponent<Button>();
[*] path = cv.transform.FindChild("PathButton").gameObject.GetComponent<Button>();
[*] field = cv.transform.FindChild("FieldButton").gameObject.GetComponent<Button>();
[*] }
[*] public void ActiveteBuilding(Button pressedBtn)
[*] {
[*] if (pressedBtn.name == "BuildButton")
[*] {
[*] if (buildopen)
[*] {
[*] //bm.DeactivateBuildingmode();
[*] house.gameObject.SetActive(false);
[*] tower.gameObject.SetActive(false);
[*] path.gameObject.SetActive(false);
[*] field.gameObject.SetActive(false);
[*] pressedBtn.image.color = Color.white;
[*] buildopen = false;
[*] }
[*] else
[*] {
[*] //bm.ActivateBuildingmode();
[*] house.gameObject.SetActive(true);
[*] tower.gameObject.SetActive(true);
[*] path.gameObject.SetActive(true);
[*] field.gameObject.SetActive(true);
[*] pressedBtn.image.color = new Color(255, 0, 255);
[*] buildopen = true;
[*] }
[*] }
[*] else
[*] {
[*] switch (pressedBtn.name)
[*] {
[*] case "HouseButton":
[*] bm.SelectBuilding(0);
[*] break;
[*] case "TowerButton":
[*] bm.SelectBuilding(1);
[*] break;
[*] case "PathButton":
[*] bm.SelectBuilding(2);
[*] break;
[*] case "FieldButton":
[*] bm.SelectBuilding(3);
[*] break;
[*]
[*] }
[*] pressedBtn.image.color = new Color(155, 120, 255);
[*] bm.ActivateBuildingmode();
[*]
[*] }
[*] }
[*] void Update()
[*] {
[*] if (buildopen)
[*] {
[*] if (!bm.isBuildingEnabled)
[*] {
[*] if (house.image.color != Color.white)
[*] house.image.color = Color.white;
[*] if (tower.image.color != Color.white)
[*] tower.image.color = Color.white;
[*] if (path.image.color != Color.white)
[*] path.image.color = Color.white;
[*] if (field.image.color != Color.white)
[*] field.image.color = Color.white;
[*] }
[*] }
[*] ScoreManager sm = GameObject.FindObjectOfType<ScoreManager> ();
[*] if(sm.money < bm.SelectedBuilding.GetComponent<house>().cost) {
[*] return;
[*] }
[*] }
[*]}
[/LIST]