mouseclick unity 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: unity left mouse button
Input.GetKey(KeyCode.Mouse0))
Example 3: onmouseclick unity
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;public class ExampleClass : MonoBehaviour
{
void OnMouseDown()
{
Destroy(gameObject);
}
}
Example 4: unity onclick object
void Update () {
}
void OnMouseDown(){
Destroy (this.gameObject);
}