- Home /
Input resets when scene changes
I have a run button in the game, and if the user is holding it down and never releases it, Input.GetKey(KeyCode.X) returns false after changing to a different scene. Is there a way to change this or a work around?
Just ran into this issue. Figured I'd bump ins$$anonymous$$d of asking a new question.
Answer by vexe · Jun 30, 2015 at 09:42 AM
The problem also occurs when using Input.GetAxis. It seems like the only work-around currently (Unity 5.1.1) is to use LoadLevelAdditive instead of LoadLevel and manually cleaning up/destroying/unloading objects in the current scene.
var allObjects = GameObject.FindObjectsOfType<GameObject>();
foreach (var obj in allObjects)
if (obj should not be destroyed) // since DontDestroyOnLoad has no effect here...
Destroy(obj);
Application.LoadLevelAddtiive(level);
Instead of iterating over gameObjects and destroying them, you could have a single root gameObject in your scene that parents all the objects you want to destroy, then you just destroy that gameObject and all its children will be gone with it.
Your answer
