You could use a couple approaches to detect mouseclicks. Just to detect mouse click, use function OnMouseOver()
{
//Whatever you want to happen when mouse is over object
}
to detect click
if(Input.GetMouseButtonDown(0))
{
//Whatever you want to happen when you left click
}
Attach this to a box for a test to get you started. This will detect when the mouse is hovering over that box object, and if you click on it.
function OnMouseOver()
{
if(Input.GetMouseButtonDown(0))
{
Debug.Log("Mouse clicked on an object!");
}
}
Another Approach is to attach a Javascript to the main camera, using RayCast. This works on a camera that moves with mouseLook. It casts a ray from the center of the screen.
function Update()
{
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast (transform.position, direction, hit, 1000))
{
Debug.Log("HIT!");
}
}
There are many other way, but I think this will give you a start. Look in Unity Script reference for more information on these techniques.