I am trying to write a text driven game just to teach myself a few things. I am wondering if there is a better way to handle a branching style of text. I am currently using “if” statements yo handle everything but I find it very confusing to get everything in order. Is there a better way to handle this? I know the code is necessarily going to function the way it is (most of it does) but I think you can see what I am trying to do with the displayed code.
Thank You!
activeText = a string that’s displayed in the GUI.
public void StateUpdate()
{
//The following is the Attack cycle.
if (Input.GetKeyDown(KeyCode.A) && attackStatus == 0)
{
attackStatus = attackStatus +1;
}
if (Input.GetKeyDown(KeyCode.A) && attackStatus == 1)
{
activeText = attackText;
}
if (attackStatus == 2) //
{
activeText = attackText2;
}
//The following is the Look cycle.
if (Input.GetKeyDown(KeyCode.L)&& lookStatus == 0)
{
lookStatus = lookStatus +1;
activeText = lookText;
}
if (Input.GetKeyDown(KeyCode.L)&& lookStatus == 1 && interactStatus == 0)
{
activeText = lookText;
}
if (Input.GetKeyDown(KeyCode.L)&& lookStatus == 1 && interactStatus == 1)
{
activeText = lookText2;
}
// if (Input.GetKeyDown(KeyCode.L)&& lookStatus == 2 && interactStatus == 1);
// {
// activeText = lookText3;
// }
//The following is the Interact cycle.
if (Input.GetKeyDown(KeyCode.I) && lookStatus == 1)
{
interactStatus = interactStatus+1;
activeText = interactText2;
}
if (Input.GetKeyDown(KeyCode.I) && lookStatus == 0)
{
activeText = interactText;
}
That is awesome! Thanks so much. I will try this out tomorrow. I think this is exactly what I needed! I will come back and make sure I thumb up or let you know how it went.
– jakieb