|
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
(comments are locked)
|
|
Add a boolean "spawned" that is initially false, and alter KillSelf() to something like this: Nice one. I probably should have mentioned that I am a complete code amateur though. Do you mind explaining how that would work? And how would I add that boolean in the script?
Nov 30 '09 at 09:01 PM
zenislev
Actually, this seems to have worked - thanks to you both!
Dec 01 '09 at 05:23 PM
zenislev
Glad to hear you got it working. As a recommendation, get some tutorials on programming - regardless of if they're C# or not. You're bound to run into some non-trivial things soon enough, where the community won't be able to help you with quick snippets.
Dec 01 '09 at 06:03 PM
Ricardo
I absolutely agree. I had intended to just play around with Unity, but it's impressed me to the point of actively wanting to learn. I can't keep on scavenging for code forever.
Dec 01 '09 at 06:17 PM
zenislev
(comments are locked)
|
|
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. Thanks for that. Seriously, even the simple stuff seems impenetrable from a zero-knowledge standpoint. OCE has been a bane of mine for a while now. Good luck to you too =)
Dec 01 '09 at 05:25 PM
zenislev
(comments are locked)
|
