- Home /
Unresponsive to touch events in android. RaycastHit2D not working anymore?
Greetings,
My game used to work perfectly in Unity Editor and Android devices, but suddenly it has stopped to work in Android, though it still works flawless within the Unity editor.
Since we have changed nothing on such code, we think it has to be something that has changed in latest Unity versions. Here is the involved code, though:
void OnGUI ()
{
Event e = Event.current;
// First treath global events
if ((e.isKey) && (e.type == EventType.KeyUp)) {
if (e.keyCode == KeyCode.Escape) {
/**
* From http://docs.unity3d.com/ScriptReference/Application.Quit.html
* "Quit is ignored in the editor or the web player."
* So don't get mad because it seems not to be working...
*/
Application.Quit ();
}
}
if (e.isMouse) {
if (e.type == EventType.mouseUp) {
Vector2 touchPoint = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint (Input.mousePosition).y);
RaycastHit2D hit = Physics2D.Raycast (touchPoint, Vector2.zero, 0f);
if (hit.collider != null) {
if (hit.collider.gameObject.name == "mainMenu") {
if (GameManager.Settings.SoundEnabled)
clickSound.Play ();
if (buttonMusic.OverlapPoint (touchPoint)) {
Debug.Log ("buttonMusic clicked");
mainMenuDisableMusic.renderer.enabled = ! mainMenuDisableMusic.renderer.enabled;
GameManager.Settings.MusicEnabled = ! mainMenuDisableMusic.renderer.enabled;
if (introTheme.isPlaying) {
introTheme.Stop ();
} else {
introTheme.Play ();
}
} else if (buttonSound.OverlapPoint (touchPoint)) {
Debug.Log ("buttonSound clicked");
mainMenuDisableSound.renderer.enabled = ! mainMenuDisableSound.renderer.enabled;
GameManager.Settings.SoundEnabled = ! mainMenuDisableSound.renderer.enabled;
} else if (buttonPlay.OverlapPoint (touchPoint)) {
Debug.Log ("buttonPlay clicked");
Application.LoadLevel ("GameSelMenu");
} else if (buttonScores.OverlapPoint (touchPoint)) {
this.StartGameServices ();
} else if (buttonAbout.OverlapPoint (touchPoint)) {
Debug.Log ("buttonAbout clicked");
} else if (buttonSettings.OverlapPoint (touchPoint)) {
Application.LoadLevel ("Settings");
}
}
}
}
}
}
I have not very clear how to debug this neither, since the step by step debugger has never worked for me with Android devices (maybe it is a pro feature...)
Comment