I've got an 'infection' system set up, which is supposed to work like this: 'uninfected' GameObject collides with 'infected' GameObject; uninfected GameObject is destroyed and an infected clone instantiated in its place.
The problem is, I've noticed that more than one clone is being instantiated sometimes. I think this might be because, since the player character is always infected, the uninfected GameObjects often collide with two separate infected GameObjects at once and the code spawns an infected clone for each of those collisions - instead of just one - before destroying the original uninfected GameObject. Here's the code I'm using:
Any ideas how to stop this from happening? I only want one infected clone per uninfected GameObject :S
Add a boolean "spawned" that is initially false, and alter KillSelf() to something like this:
answered Nov 30 '09 at 05:59 PM
You can declare a variable to be a boolean at the beginning of the script by using:
var spawned : boolean = false;
I'm pretty new to this code stuff too, but I'm also having similar collision problems. The one thing we have in common is the OnCollisionEnter (seems to like repeating things you don't want it to), and doing this same kind of thing didn't help me. I'm actually still stuck on this, good luck to you though.
answered Nov 30 '09 at 10:06 PM