Invoke'd function resets values of certain fields
So I have a very basic script along the lines of this: public class GameManager : MonoBehaviour { public int level;
// Start is called before the first frame update
void Start()
{
level = 3;
}
public void resetAndStuff()
{
Invoke("reset", resetTime);
}
public void reset()
{
SceneManager.LoadScene("Level" + level, LoadSceneMode.Single);
}
}
The problem is, for some reason the scene Level2 is loaded.
I know the value is never changed anywhere else in code, I even renamed it to confirm it was only used in those two places. I know that the entire script isn't being reset, as other serialized fields are still there, yet somehow level is set to 2 and not 3.
the method resetAndStuff (it does other things) is called from another GameObject, and uses a SerializedField of the GameObject this script is a child of to get the script instance.
Can you try adding a log to reset
to log the level name? Can you also try calling Scene$$anonymous$$anager.LoadScene("Level3", LoadScene$$anonymous$$ode.Single);
and see if it does what you want?
Your answer
Follow this Question
Related Questions
Broken Jump Physics 0 Answers
Animation only plays once 0 Answers
Few opened editor windows 0 Answers
How can I access the Unity 5 First Person Controller per script? 1 Answer
UI Text Not Updating 1 Answer