unity click on object code example
Example 1: gameobject on click unity
private void OnMouseOver() {
Debug.Log("Hovering over GameObject");
}
Example 2: unity click on gameobject
using UnityEngine;
public class nameOfClass : MonoBehaviour
{
bool isObjectClicked;
void OnMouseDown()
{
isObjectClicked = true;
}
void OnMouseUp()
{
isObjectClicked = false;
}
}
Example 3: unity click object
void OnMouseDown()
{
Destroy (this.gameObject);
}
Example 4: unity onclick object
void Update () {
}
void OnMouseDown(){
Destroy (this.gameObject);
}
Example 5: detect object click unity
void Update () { } void OnMouseDown(){
Example 6: how to click a gameobject in unity
using UnityEngine.UI;
public Text text;
text.text = "new text";