Variables not saving

Taking Ben’s advice I have been building on what I have learned so far. I am building a simple guessing games that flips through multiple scenes depending on the players choices. the code is working as intended but the issue is when I run an if statement to see where the player should be taken next, the variables from the previous two scenes aren’t stored. any suggestions or what lecture I should look at for help?

this is a piece of the code, the log shows the variables are both zero and therefore it wont load the corresponding scene. in the scene where the function is called for each of these works properly and varies so I know they are working, just not saving for another function use even though they are in the same class.

public void winlose()
{
Debug.Log("winlose function start :: p1choice: " + p1choice + " aichoice: " + aichoice);
if (p1choice == 1 && aichoice == 1) { Application.LoadLevel(“R2”); Debug.Log(“Level load requested for:R2”); }
else if (p1choice == 1 && aichoice == 2) { Application.LoadLevel(“PCR”); Debug.Log(“Level load requested for:PCR”); }
else if (p1choice == 1 && aichoice == 3) { Application.LoadLevel(“RCS”); Debug.Log(“Level load requested for:RCS”); }
else if (p1choice == 1 && aichoice == 4) { Application.LoadLevel(“RCL”); Debug.Log(“Level load requested for:RCL”); }
else if (p1choice == 1 && aichoice == 5) { Application.LoadLevel(“SVR”); Debug.Log(“Level load requested for:SVR”); }
else if (p1choice == 2 && aichoice == 1) { Application.LoadLevel(“PCR”); Debug.Log(“Level load requested for:PCR”); }

1 Like

Helo @Shakiel, how are you?

Could you use sites like paste bin to share your code?
Or you could use (just take out the quotes):

[“code”]

//CodeBlock

["/code"]

void Start()
{
    Example ():
}

Privacy & Terms