I dont understand why my script wont run on button press. I have used a similar code layout on another “game” i used to learn on and it works.
working code
using UnityEngine;
using System.Collections;
public class Build_Quarry : MonoBehaviour {
// stone values
public UnityEngine.UI.Text quarryDisplay;
public int quarry = 0;
public int newquarrypclick = 0;
void Update () {
quarryDisplay.text = "Quarries: " + quarry;
}
public void Clicked(){
quarry += newquarrypclick;
}
}
broken code
using UnityEngine;
using System.Collections;
public class Turn : MonoBehaviour {
public int StoreSize = 1;
public int maxStock= 10;
public int currentStock = 5;
public UnityEngine.UI.Text StoreSizeDesc;
//public UnityEngine.UI.Text StoreSizeDescDetailed;
public UnityEngine.UI.Text Stocktext;
public void Clicked(){
maxStock = 25;
Stocktext.text = currentStock + "/" + maxStock;
StoreSizeDesc.text = "Bicycle cart.";
//StoreSizeDescDetailed.text = "You have a small coffee cart that trails behind your bicycle.";
}
}
I have attached an image of the script area of my button.
I’m really only interested in learning currently. There is no reason why things are coded how they are other than thats how I have found it to work in the past.
I just dont understand why one script works on click, and the other does not. Thanks in advance unity hivemind!