- Home /
Detecting Click on Object Issue
Hello!
I'm having some difficulty detecting clicks on a gameobject. Nothing happens when I click on the object, but after some experimenting, I found that the click is detected on other parts of the screen. These areas appear to change depending on where on the scene the camera is directed. The game is 2d, top-down, and the camera can scroll along x/z axes.
There is a GUI matrix on the scene, not sure if that might be linked to the problem.
Here's the code I'm using to detect clicks.
void OnMouseDown()
{
Debug.Log("Pre-Scene check click detected " + Input.mousePosition);
// Check if the Scene is 1
if(sceneName == "1")
{
Debug.Log("Click detected");
}
}
Any help would be greatly appreciated. Let me know if you need any more info to solve this mystery!
Update 1
Added mouse position and Camera.main.ScreenToWorldPoint(mousePosition) to the debug. The y value of the ScreenToWorld is 65.8, whereas the turret is around 0.3. Could this have something to do with it? Image of debug below.
After changing the gui matrix and doing your stuff restore it to the original, just is case.
Thanks for suggestion. Disabled the GUI.$$anonymous$$atrix. Seems pretty much the same.
Nail on the head. Thank you. A while back, I placed a plane over the camera intending to use it for a menu screen. If you'd like to convert to answer, we can close this one.
Answer by iwaldrop · Feb 17, 2013 at 10:45 PM
OnMouseDown does get a mouse click normally. If its not then mayber there is something that is physically getting in the way, or the object that you're trying to click doesn't have a collider.
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Collider priority with onMouseDown() 2 Answers
Need help with onMouseDown () 1 Answer
OnMouseDown working only sometimes 1 Answer