In my scene, I click on a GUIText to instantiate a tank at a spawn point. The Tank script has an OnMouseDown function which selects the Tank (placing the word “Tank” on the screen via another GUIText). The player starts the game with 1 Tank already. The Tank that is already in the scene works perfectly, but for the instantiated Tank the OnMouseDown function is never called. (I checked using the print command). Just for testing purposes I placed several Tanks in the scene before hitting play and they all work perfectly. OnMouseDown only fails to work for the instantiated Tanks.
The prefab has both a collider and the script attached. I paused the game just to double check that everything was identical between the first Tank and the instantiated version, and it is. Only the names of the objects are different (Tank1 and Tank2). Originally the names were the same, but I changed that hoping it would solve my problem, obviously it did not.
Thank you for your time. I hope someone can help me with this problem.
Edit: I solved the problem, but it creates another issue. A Trigger Collider on an empty, one which I’ve set up to perform functions that I will add later, is present at the spawnpoint, and was blocking my mouse click. So my new issue is: How can I prevent a Trigger Collider from blocking OnMouseDown for an object inside the Trigger?