- Home /
Instantiated GameObject collision without script repetition?
So in my project I have the player "playerTank" and I can control the player correctly, and I am vaguely familiar with collision detection. However, there are several randomly generated "walls" that I have instantiated, that I want to impede player movement. Keeping in mind that my movement scripts are turn-based and not physics based, is there any way to identify all of the walls, and walls' clones (wallclone1, wallclone2, etc) without attaching a script to each one? Perhaps I can assign them to a parent during generation, and somehow specify a collision with all of GameObject wall's children? If there are any solutions, I'd love to hear them <3.
Answer by robertbu · Jul 29, 2014 at 05:25 AM
The typical solution is to use tags. Give all your walls the same, unique tag. Then you can do:
var walls : GameObject[] = GameObject.FindGameObjectsWithTag("Wall"):
Your answer
Follow this Question
Related Questions
collision.gameObject returning parent. 1 Answer
Instantiate prefab as Child to remove and re-do later 2 Answers
Creating new Transform from existing objects Transform to Instantiate object 1 Answer
Instantiate Terrain Object as child of Empty Game Object 1 Answer
How to destroy a parent object when child object is collided 1 Answer