- Home /
The question is answered, right answer was accepted
Unity3D Destroying animation after its played
So what im trying to do is after the destroy player function was called I want my player to play an animation and then to delete the object and the animation that its played.At the moment it plays the animation and then creates a new player object ,but the animation is still on screen and its not destroyed.Please help me.
function destroyPlayer(dpos : Vector3) { var player1 : GameObject = Instantiate(playerDeathObj,dpos,playerDeathObj.transform.rotation) as GameObject; player1.animation["death"].speed = 3.5; yield WaitForSeconds(0.5); Destroy(player1); }
After running a Debug.Log after the WaitForSeconds i noticed that destroy player is not even reached but if i try to put it on the Update function it destroys my new object.I really dont know what to do.Help me please.
also if i remove the yield WaitForSeconds it destroys it like it should but the animation is not played anymore...
Answer by Kiloblargh · Dec 15, 2013 at 05:22 PM
playerDeathObj
is a reference to a prefab and as such it does not have a transform.rotation, so your Instantiate is wrong. You need to set the rotation to the transform of something already in your scene.
Destroy
can take a second argument that is the wait time, making the yield WaitForSeconds
redundant.
Finally. you don't always need to Destroy things; SetActive (false)
is better in most cases.
I did not know Destroy can take wait time argument.Thank you very much that totaly solved my problem :D .
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Animation Autostart 1 Answer
Make the Animation panel's 'record mode' record another property. 0 Answers
how do you make walls close in after an object is destroyed? 0 Answers
Problems with movement and animation 1 Answer