I have finished S04, and now I know how to add UI buttons. So now instead of giving a keyboard input to the text adventure game, I want to add a UI button input.
My script looks like this:
public void state1 () {
Question.text = ("Q1");
Choice1.text = ("text1") ;
Choice2.text = ("text2");
Choice3.text = ("text3");
}
I have 4 UI texts which changes depending on the state.
3 of the UI text have been made to a button the “Choice#” texts.
Problem
I want to add a UI button which will change state depending on what state it currently is in.
I could add the following code directly under the state and it will work for keyboard input. So if I put the following code, pressing R would take me to state2 only if it is in state1.
if (Input.GetKeyDown(KeyCode.R)) {myState = States.state2;}
Adding a UI button, I am forced to make a new method. So how can I make the UI button change the state depending on what state it is in currently.
Solution
So what I did was,
public void Button1 () {
if (MyState == States.state1) {MyState = States.state2;}
else if (MyState == States.state3) {MyState = States.state4;}
}
So now if in state1 button takes me to state2, if in state3 it takes me to state4.
It is a bit more complicated than adding a keyboard input. I was having trouble making the button do a different thing each time.
If there is an easier way please tell me, thank you.
Sorry for not making myself clearer the first time. newbie here. I hope I have made myself a little bit clearer now.