Hi all
I am making a small game on android and have a problem with the input.
When I push a button and detect what button and use Application.LoadLevel(“SomeLevel”) to load the next scene, the input gets carried over to the next scene. So if there’s a button on the same location on the new scene, it gets activated.
Can I clear the input or do I have to add a delay after loading a scene before any buttons can be activated?
Rasmus
I have fixed it by changing it to MouseButtonUp instead of MouseButtonDown. It can also be fixed by using “if (Input.touchCount == 1)” so you know there’s at least one finger on the display.
It also happens if I use the buttons on the phone “HTC Desire”, back key will jump several screens back if I push it. Fixed that with GetKeyUp instead of just GetKey.
Actually if you were to detect touch on LateUpdate() that should be a better solution in terms of loading your new scene after the current scene is finished handling the touches. This works well for me. Note that instead of using mouseButtonUp or down I am using the input.touchcount and checking the touch against my collider on the button with the overlappoint method. I did this instead on the mouse events for android etc. because unity keeps warning those are not recommended for touch devices. Bit of pain to begine with but works well once you have it.
void LateUpdate () {
if (Input.touchCount > 0) {
if (Input.GetTouch (0).phase == TouchPhase.Ended) {
if (bc2d != null && bc2d.OverlapPoint (Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position))) {
Debug.Log ("change scene touch about to load " + sceneToLoad + " from " + SceneManager.GetActiveScene());
SceneManager.LoadScene (sceneToLoad);