Raycast hit selecting all objects via tag?

In one class I’m instantiating a prefab made of components with various tags. If I click a prefab it increments a counter in GUI class then destroys the object.

TileObjects[x,y] = (GameObject) Instantiate(tileTypes[ Random.Range(3, tileTypes.Count) ], new Vector3(x, y, 0.1f), Quaternion.identity) ;

In another class attached to the prefab I’m testing the clicked object but when I click the object it adds 1 for each prefab tagged ‘Coin’, it only supposed to add +1 to the counter .

ray = Camera.main.ScreenPointToRay(storeInputPos);
if (Physics.Raycast(ray, out hit, 100)){

if (hit.collider.gameObject.tag == "Coin"){
	Destroy(hit.collider.gameObject);	
	GameManager.coins += 1;
   }
}

Any clues?

Because you added the script to the prefab, so each instance of the prefab will handle the raycast. You have to attach this script to an external object and not inside the prefab itself.

Thanks for that, I just created a dummy object in the scene, attached the script to that and took it offa the prefabs - works!