unity mouse 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: unity left mouse button
Input.GetKey(KeyCode.Mouse0))
Example 3: unity mouse click position
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit))
{
return hit.point;
}
Example 4: GetMousebuttonDown unity
if (Input.GetMouseButtonDown(1))
Example 5: unity mouse click screen
var cameraloc:Camera;
var mousePos:Vector3;
var worldPos:Vector3;
cameraloc = GameObject.Find("Camera").GetComponent(Camera);
mousePos = Input.mousePosition;
worldPos = cameraloc.ScreenToWorldPoint(mousePos);