public function for UI button is not changing bool. Works fine with GetButtonDown.
Super simple stuff here, not sure what is going on. I decided to change a GetButton to a UI Button. So I created a public function called Spinstart() for the UI button OnClick() to flip the exact same B1 bool the Getbutton was using (which is now commented out.) At runtime it is behaving like the B1 in the public function is a duplicate of the actual B1 I defined up top and/or reading in the UPDATE(). a Debug.Log in update() and Spinstart() show different values. How can this be? update() never sees B1 = true
public class spin_me : MonoBehaviour {
public bool B1; // Use this for initialization
void Start() {
B1 = false;
}
// Update is called once per frame
void Update() {
// B1 = Input.GetKeyDown(KeyCode.A);
if (B1) {
*stuffhappens when true, but B1 is never true using the public function, GetKey still works.*
B1 = false;
}
}
public void Spinstart() { B1 = true; } }
Thanks for the help in advance.
quick update, if I redefine the B1 as static ins$$anonymous$$d of public, it works. WHY? I shouldn't have to do that, right?? I mean is there risk in doing this or is it the correct solution?
Your answer
Follow this Question
Related Questions
Call function of a MonoBehaviour class in another class 0 Answers
Passing parameters in function efficiency? 1 Answer
OnTriggerEnter not working 2 Answers
How do I assign values to variables in the Update function only ONCE? 1 Answer
How do you create a generic function for custom types that are inherited from a generic class? C# 1 Answer