Hello,
I have a few objects around my scene, such as a newspaper, a chair and a chocolate bar (tagged correspondently).
What I want to do, is that when the user clicks on either of these objects - it prints to the console the 'tag' or name of the current selected object.
I've been playing around with raycast from camera to mouse position, and I can never get it to work. I have to place a unique script on each of the objects like this:
#pragma strict
function Update(){
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (collider.Raycast (ray, hit, 100.0) && Input.GetButton("Fire1")) {
Debug.DrawLine (ray.origin, hit.point);
print("hitting chair");
GameControl.ShelfClicked = true;
}
}
Can I not just have a 'central control' where it works like this:
If chair has been 'raycast' && Fire1 - print 'touched chair'.
If newspaper has been 'raycast' && Fire1 - print 'touched newspaper'.
and so on ... Instead of placing the raycast script into each object?
Hope that makes sense, Thanks!