How can i change a state when a button is pressed?
Hello, I'm trying to do a text adventure game, but I'm faced upon doing it either by multiple scenes and OnClick script, or doing it with enum States. i would like to know if it is possible to change a state when a button is clicked. If it is, would you be so kind to enlighten me through it? As you may notice, I'm still a n00b in unity affairs.
Answer by dhore · Dec 13, 2015 at 01:05 AM
If you're using a UI Button you can just make a public function in your script with a parameter to pass it the enum to change the state to, and then call it in the button's OnClick event in the inspector (if you have trouble finding that you can check out this post).
Here's an example of what I mean by the public function:
public enum MyState { something, somethingElse, nothing };
MyState state; // variable
public void ChangeState(MyState newState)
{
// call this function from the OnClick of the button and give it a new state
state = newState;
}
$$anonymous$$an i tried it out as soon as i read it and it did what i was planning! Thank you so much! Sorry for the late response, i was out of home for some time. Really loved it man , thank you!
Your answer
Follow this Question
Related Questions
Expose method with Enum parameter to editor 0 Answers
How to do Unlockable Items for a Character Collection Clicker Game? How to disable buttons? 0 Answers
Trigger when holding key 1 Answer
How to change HotKeys for UI Navigation? 0 Answers
With the new unity input system. How do I setup UI buttons like in the old system. 0 Answers