- Home /
Animation Finished
Hey Guys,
I need some help with this one. I have an animation of one of my characters falling asleep, and another animation of them sleeping.
The problem I am having is I need to start the sleeping animation after the falling asleep animation has finished. I have tried using IsPlaying and PlayQueued but I can't seem to get it just right. Anyone have any ideas of some JavaScript that could help with this?
Thanks
P.S When will my questions and answers but posted without waiting for an administrator to approve it first?
Answer by LightSource · Apr 18, 2013 at 07:04 PM
Use yield WaitForSeconds if your desperate or just post your code and we will see what we can do.
20 karma is needed to post without moderator approval I believe.
I tried yield, it said it couldn't be a Coroutine. This is the Script I am using IGG (InGameGUI) refers to another scrip.
function Sleeping()
{
sleeping = true;
woddlArt.animation.Play("Snooze");
zs.Play();
}
function Update()
{
if(IGG.sleeping && !sleeping)
{
move = false;
woddlArt.animation.Play("Sleep");
if(IGG.timer2 <= -35)
{
Sleeping();
}
}
this way it kinda works, but its unreliable as it depends upon performance of hardware to look good.
Yield cannot be used in an Update function because you can't halt the engine itself. $$anonymous$$ake a new function outside Update with the WaitForSeconds component and call that separately.
yield can only be used in a coroutine. something like:
IEnumerator SleepDelay()
{
yield return new WaitForSeconds(2);
woddlArt.animation.Play("Sleep");
}
you call the function in update by using:
StartCoroutine(SleepDelay());