How to tell if an object has been clicked in Unity code example
Example 1: unity check when clicked on object
void Update()
{
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
Debug.Log("This hit at " + hit.point );
}
}
Example 2: unity if gameobject is clicked
void OnMouseDown()
{
Debug.Log("Mouse is down")
}
void OnMouseUp()
{
Debug.Log("Mouse is up")
}
void OnMouseClick()
{
Debug.Log("Mouse is clicked (down then up its 1 click)")
}
Example 3: detect object click unity
void Update () { } void OnMouseDown(){