Subtracting from a variable through button clicks
Hi everyone I'm pretty new at unity (and coding for that matter), but I can't seem to figure out how to make the button subtract from the variable. I've tried adding the script to a game object, making it an OnClick event, but that didn't help.
public class Costs : MonoBehaviour { public int myenergylevel = 40; Selectable button;
void TaskOnClick()
{
button = gameObject.GetComponent<Selectable>();
Debug.Log(button.interactable.ToString());
myenergylevel = myenergylevel - 6;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612115553im_/https://answers.unity.com/themes/thub/images/avi.jpg)