I now have enemies in the level, yay! However, it's difficult to get rid of them, lol! I've written a script so when the main character collides with the enemy, it plays the hit animation and that works great. However, if the character is playing the "spin" or "jump" animation, I need the enemy to be destroyed. Here's what I have so far: Code (csharp): function OnTriggerEnter (other : Collider) { if (other.name == "moto_bug") { if (!animation.IsPlaying ("spin")) Destroy (other.name == "moto_bug"); } else animation.CrossFade("dies"); } But it's not happy with the "Destroy..." line at all for some reason. I've tried a whole bunch of different things in those brackets but nothing works! Just for clarification, the script is added to the main character and not the enemy. Any ideas? Mike
Not working, I've now got some really weird goings on though! Now, for some reason, when I collide with the badnik the hit animation never plays and the badnik doesn't get destroyed whether the spin animation is playing or not. Also, the ocean, which I had triggered to play the falling animation, seems to be combining some of my other scripts for some reason. Now, when I hit the ocean, I get the debug message saying I've hit a badnik, the hit animation plays, and the character gets thrown in the air like the spring animation (But for some reason this automatic reaction doesn't work on the spring itself!) This is quite mental, lol! Mike
Destroy (other); will simply remove the collider. Instead you want to delete the whole game object. thus Destroy (other.gameObject);
Nope, still not working right Here's what I've got now: Code (csharp): function OnTriggerEnter (other : Collider) { if (other.name == "moto_bug") { if (!animation.IsPlaying ("spin")) Destroy (other.gameObject); Debug.Log ("Destroyed Badnik"); } else animation.CrossFade("dies"); Debug.Log ("Hit by Badnik"); } For some reason, the badnik isn't destroyed when the spin animation is playing, but it is destroyed if any other animation is playing! I can spin through the thing all I like and not get it but if I just stand still or run through it, it'll be destroyed! I can't get my head around it fully. Any ideas? Mike
Aha! The exclamation point means NOT. So it's saying if you're NOT spinning, kill the badnik, and if you are then it won't kill it. So just remove the "!" on line 3.
Thank you!!!! Oh dear, I can't beleive I never thought to get rid of the "!"!!! It works and it's great! I'll have to work on a destroy animation now! Right, on this happy note, I'm packing it in for the night and getting ready for bed. Hopefully I'll be able to work on this more next weekend! Goodnight all, and thanks for the help the past few days! Mike