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?