unity detect click code example
Example 1: how to detect a mouse click in unity
using UnityEngine;
using System.Collections;
if (Input.GetMouseButtonDown(0)) {
} else if (Input.GetMouseButtonDown(1)) {
} if (Input.GetMouseButtonDown(2)) {
}
Example 2: gameobject on click unity
private void OnMouseOver() {
Debug.Log("Hovering over GameObject");
}
Example 3: detect object click unity
void Update () { } void OnMouseDown(){
Example 4: how to click a gameobject in unity
using UnityEngine.UI;
public Text text;
text.text = "new text";