Hi! I want to check if player click mouse on object, movie will play.
I put Input.GetMouseButton (0) function on the object but if click position is not in object,this script will run too
Please tell me how to to this and I want to know how to check mouse position in “Object area”,
I know about use Raycast to get mouse position but I don’t know how to check if my mouse position is in my object area,
how to do this?
Thanks!
Make sure your object has a collider then try this
function Update () {
if (Input.GetMouseButtonDown(0)) {
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
if (hit.transform.name == "MyObjectName" )Debug.Log( "My object is clicked by mouse");
}
}