- Home /
Question by
Babilinski · Nov 05, 2011 at 01:57 PM ·
objectclickablec
clickable object
I want to make an object clickable, what code do i use ? all the references i found where in java =(
Comment
Best Answer
Answer by Catlard · Nov 05, 2011 at 03:43 PM
Try using this in an update function. Just change the tag to whatever the tag of the object you want to click will be.
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, 100.0))
{
myTarget = hit.collider.gameObject;
if(myTarget.tag=="tagOfTheObject")
{
//DO STUFF
}
}
}