- Home /
Destroy All of One One object on collision
Hey, basically i have blocks raining down at random intervals, and when the blocks stack up to a ceratin point, i want them ALL to be destroyed. I also want it so that once it hits the thing destroying them all, the script is enabled. Since it is 2d, if it collides with the thing and destroys it, they will never stack.
Let the thing that destroy the blocks ( I'll call it destroyer ) have a script that stores an array of transform variables. As soon as any block is instantiated, the first thing you do is add its transform to the array being stored in script of the destroyer.
Next, the destroyer detects when any block hits it, this can be done using OnCOllisionEnter function. As soon as a block hits the destroyer you access all the elements stored in the array using a for loop and destroy them one by one by running the loop required number of times
Answer by seedoubleyou · Jan 14, 2012 at 09:13 PM
There's probably a bunch of different ways to do this, but I'd probably have a master Empty GameObject that checks for when your block pile reaches a certain height (you could do this with a Collider) then it Broadcasts a message to all the blocks, destroying them.
Your answer
Follow this Question
Related Questions
Ignoring collisions with clones 3 Answers
Destroy an object with another one. 1 Answer
Pacman eating (destroying) pellets on collision! 0 Answers
Collision with a coin 0 Answers