I have an prefab with a simple 3D cube with .js attached to the prefab itself:
private var ray : Ray;
private var hit : RaycastHit;
function Update () {
if(Input.GetButtonUp("Fire1"))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit))
{
Debug.Log("touched: " + this.name);
}
}
}
Then I drag 2 copies of this prefab into the scene. When I test the mouse click on any of them, The event fire twice:
"Touched: pf_Cube01" "Touched: pf_Cube02"
How can I make them unique so that when I click on pf_Cube01, I only get:
"Touched: pf_Cube01"
Thanks!