- Home /
OnMouseDown not Working becuase of camera distance !!!!
Ok here is the thing I have a script attached to a sphere with OnMouseDown function on it with a simple debug.log but as matter of fact my camera should be very close to my object in order to work. how can I fix this ?????
I believe you have one object with a collider / Raycast target between your camera and your object which intercept the event.
Ins$$anonymous$$d of implementing the On$$anonymous$$ouseDown
function, can you try to implement the interface and seee if you have better results? (Don't forget to add a PhysicsRaycaster
to your camera and to attach a 3D collider to the object)
using UnityEngine.EventSystems;
public class Example : $$anonymous$$onoBehaviour, IPointerDownHandler
{
//Detect current clicks on the GameObject (the one with the script attached)
public void OnPointerDown(PointerEventData pointerEventData)
{
//Output the name of the GameObject that is being clicked
Debug.Log(name + "Game Object Click in Progress");
}
}
Your answer
Follow this Question
Related Questions
Ways to make OnMouseDown (or a single script) differentiate between different colliders/sprites 1 Answer
How to run the Coroutine of one script in another using the onMouseDown function ? 2 Answers
Trying to change character model on mouse down 1 Answer
Odd change in behaviour after I rearranged project files 0 Answers