Recently I saw a strange thing. Unity is reading both if and else statements at same time. Here’s the code -
void SetupControls()
{
if(PlayerPrefs.GetString(“ShowMM”) == “Yes”)
{
Debug.Log(1);
}
else if(PlayerPrefs.GetString(“ShowMM”) == “No”)
{
Debug.Log(2);
}
}
And i am getting both 1 and 2 as log in console.
What to do to fix this?? I tried restarting unity and system, nothing worked
AND I AM DOUBLE SURE THAT IN PLAYERPREFS IT IS SET TO “Yes”!
Hey!
First of all, visit this link, because it`s unbelievably uncomfortable to read unformatted code. https://forum.unity.com/threads/using-code-tags-properly.143875/
Secondary, Look at the code below, it produces output of one. I guess it`s impossible to run both if-else conditions at the same time. Maybe you output 2 somewhere else?
string s = "example";
if (s == "example")
{
Debug.Log(1);
}
else if (s == "notexample")
{
Debug.Log(2);
}
I also tried re-installing unity and visual studio, still unity performing both if and else together. I am in a huge trouble, please help!