- Home /
The question is answered, right answer was accepted
If statement not working properly
here is the code
if (level_completed == 1) { string temp = "Level_" + (level_current + 1); Debug.Log(temp); bool temp1 = PlayerPrefs.HasKey("temp"); Debug.Log(PlayerPrefs.GetInt("temp")); Debug.Log(temp1); if (temp1==false) { PlayerPrefs.SetInt(temp,0); } }
and my problem is temp1 is returning false even though i am having a key as temp string in my playerprefs.
You should really
Use code blocks here (4 spaces in front of your code lines) ins$$anonymous$$d of inline code for readability.
Give proper names to your variables. It's harder to understand what you're trying to do when all your variables are called "temp".
Aside from that, I just tested this, and it works fine for me.
Where did you set the int ? Cause It doesnt seem like u have done it there.
You check level_compledeted for 1 then u make a string out of Level_+ levelcurrent+1 then u print it then u read the temp key into a bool but its never set so maybe thats your issue?
didnt worked much with playerPrefs so I cant say it without testing a lil bit. $$anonymous$$aybe I can say more if you provide more code
yes i just notified it,i used temp in double quotes,thanks.
Follow this Question
Related Questions
Disabling function of a key 1 Answer
Using if/else statements in GUI 1 Answer
Checking nulls almost all the time! Is this normal? 1 Answer
Rotating A Camera Back and Forth 1 Answer