Get animation to play only after another has finished

Ok so I’m going crazy trying to figure out why this isn’t working. In my game the player has the option to fish, and when they hold down “E”, first the Fishing_Cast animation should play ONCE and then the Fishing animation should play until the player let’s go.

Here’s my code so far for the animations: (It’s in an if statement checking if E is pressed)

if (!player.animation.IsPlaying("Fishing_Cast") && !hasCast)
{
    player.animation.CrossFade("Fishing_Cast");
    hasCast = true;
}
else if(!player.animation.IsPlaying("Fishing_Cast") && hasCast);
{
    player.animation.CrossFade("Fishing");
}

Should this not work?

Right now the player never casts, and instantly goes to the Fishing animation. If i comment out player.animation.CrossFade("Fishing"); then the player casts once then stops, which should be how it works either way. the hasCast is to check whether the Fishing_Cast animation has started.

Please, any help would be awesome, I am SO stuck right now. Thanks.

It appears to me that player.animation.IsPlaying(“Fishing_Cast”) is always resolving to false and so on the first frame you press E, hasCast is false and so it does lines 3 and 4, but then the following frame, because you are still pressing E, hasCast is now true and the script executes line 8.

A better solution would be to use an animation controller so that you don’t have to hard code things like “Fishing_Cast” and “Fishing”

Your code is incredibly wrong - heh

(1) never use “else if” if you’re a beginner. that sentence is clear right? so, delete that from your code.

(2) use Debug.Log statements everywhere. you’ve got it right?

(2) try writing “break away” code. something like this … notice the return statements

if ( the animation is playing )
{
// apart from anything else, if an animation is alredy underway,
// just do nothing at all
Debug.Log(“I’M IN AREA 1…”);
return;
}

if ( the player has cast )
{
// again, just do nothing at all here…
Debug.Log(“I’M IN AREA 2…”);
return;
}

Debug.Log(“I’M IN AREA 3…”);

And so on … your logic is impossible to understand so you’ll have to figure it out yourself.

But it’s very very easy if you use “breakaway” code … and Debug.Log statements.