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:
var follower : GameObject;
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.name == "Player" || collision.gameObject.name == "FollowerInfectedPrefab" || collision.gameObject.name == "FollowerInfectedPrefab(Clone)"){
KillSelf();
}
}
function KillSelf () {
var followerInfected = Instantiate(follower, transform.position, transform.rotation);
Destroy(gameObject);
}
Any ideas how to stop this from happening? I only want one infected clone per uninfected GameObject :S