- Home /
Make Animated object disappear after it animates
I'm new to Unity, however, I have searched for hours for this and can't seem to find the right solution. I have tried many different scripts. Asking on here was my last resort. Here is what I'm trying to do. I have a animation called "tyrant_zombie" and a "trigger" the trigger sets off the animation when I'm close to the "tyrant" (that all works great!) However, I would like the tyrant to disappear after its attack animation. This is what I have tried so far and its not working.
function PlayAndDisappear(){ animation.Play("attack01"); WaitForSeconds(animation["attack01"].length); gameObject.SetActive(false); }
and a few others I can't remember. Can someone please help me? It must be an easy solution! I just need to know the scrtip to add to the tyrant_zombie to make him disappear after he animates. thanks in advance.
Answer by SmalleeStudio · Nov 10, 2014 at 07:15 AM
gameObject.SetActive can not make object "Invisible"
Please use :
Destroy(gameObject) ;
it may Unload whole object so it's better way if you no longer need that gameobject
DON't just make thing invisible, it may cause your game lagging.
Thanks for the response but I actually ended up figuring it out a few hours after posting this question. Here is the script I used and it worked great!!!!
function OnTriggerEnter(other : Collider)
{
if (other.gameObject.tag == "Player")
Destroy(gameObject);
}
Your answer
Follow this Question
Related Questions
Duplicate Object, Lose Animation 0 Answers
object dissappear and reappear 1 Answer
Objects disappear after building 1 Answer