- Home /
OnMouseDown() is not working in the GUITexture
Follwing module is attached in GUITexture, however there is no reaction in OnMouseDown(). Please help me. I couldn't find any proper answer in this page.
using UnityEngine;
using System.Collections;
public class SceneMove : MonoBehaviour
{
public string SceneName;
public void OnMouseDown(){
print ("LoadLevel");
Application.LoadLevel( SceneName );
}
void update()
{
}
}
I tested your code and it works. So please specify what is the exact output that you expect.
Have you added any colliders? In know that On$$anonymous$$ouseDown will work if your GameObject got some kind of collider
@Super$$anonymous$$asterBlasterLaser: that's not correct; GUIText and GUITexture objects do not require colliders.
Thank you for your answer,as above answer, GUITexture is not needed collider. I have wresled with this error for hours. But not found the solution.
Well, it works fine here. Try making a new empty project, create a GUITexture, and attach the script. You'll see it works as expected.
Answer by Calum-McManus · Apr 28, 2014 at 01:22 PM
there are no errors in your code, the only thing that it could be is that you are not clicking on a Collider. if you want this to work when ever you click, just put a box taking up the whole screen then turn of its renderer and attach this script to it.
Indeed, it should work on a GUI layer object or a collider, my advice would be to use a collider ins$$anonymous$$d if you really can't get a GUI-texture to work, although it should and has worked when I tested it. You could always try doing the OnGUI function and make a texture layer using that and see if it works.