unity mouse click on object code example
Example 1: unity mouse click position
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit))
{
return hit.point;
}
Example 2: unity click object
void OnMouseDown()
{
// this object was clicked - do something
Destroy (this.gameObject);
}
Example 3: detect object click unity
void Update () { } void OnMouseDown(){ // this object was clicked - do something Destroy (this.gameObject); }