- Home /
How to create a delay so object isn't instantiated until after an animation finishes?
Hello I'm working on a RPG. I have a character finished (via Blender(great program)). The animation is done. I'm now trying to master the implementation of animation inside Unity.
My current problem is that when I have the player do the animation for making a campfire and then instantiating an instance of the campfire prefab, the campfire is created right when the animation starts. I don't want the campfire to be created until the animation is completed.
Is there some way I can either tell it to wait until the animation is done? Otherwise it would be good enough if I could just put a short delay in between the animation start and the campfire being instantiated.
Here is the code I have working right now:
var newObject : Transform;
function Update () { if (Input.GetButtonDown("Jump")) { animation.CrossFade ("MakeGround"); var creation = Instantiate(newObject, GameObject.Find("spawnPoint").transform.position, Quaternion.identity); } }
So what can I do?
Thank you very much.
If you want to see the game, I can upload my progress to my website. It would only take about 2 minutes.
Answer by 3dDude · Aug 02, 2010 at 06:19 PM
try this :
var newObject : Transform; var animationTime : float = 5;
function Update () {
if (Input.GetButtonDown("Jump")) {
animation.CrossFade ("MakeGround");
makeCampFire();
}
}
function MakeCampFire () {
yield WaitForSeconds(animationTime);
var creation = Instantiate(newObject, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
}
Thanks! Works perfectly. I had to adjust the ti$$anonymous$$g, but the script is great.
Answer by Flynn · Aug 02, 2010 at 06:26 PM
Unity 3 will be supporting animation events, so when it comes out, be sure to look those up too.
Uh... you mean these, that are already available with Unity 2.6.x? -- http://unity3d.com/support/documentation/Components/animeditor-AnimationEvents.html
Your answer
Follow this Question
Related Questions
Better way to delay a function for a few seconds? Javascript 1 Answer
how do you add camera lag or delay for flight sim 1 Answer
Wait and fading script 1 Answer
adding a delay to shooting 2 Answers
Time.time button delay trick causing NaN 0 Answers