unity onclick gameobject 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 onclick object
void Update () {
}
void OnMouseDown(){
Destroy (this.gameObject);
}
Example 4: how to click a gameobject in unity
using UnityEngine.UI;
public Text text;
text.text = "new text";