- Home /
Why does my animation not play? idle overrules animation?
Hello,
I have problems with my animations: my "Stab" animation wont play and i think it is because of the idle because when I comment out the idle animation it plays just fine Here is my script:
var player : GameObject;
function Start () {
player = GameObject.FindGameObjectWithTag("Player");
}
function Update () {
if(player.GetComponent(CharacterMotor).grounded == false){
animation.CrossFade("Jump",0.3,PlayMode.StopSameLayer);
}
else if(Input.GetKey(KeyCode.W)){
animation.CrossFade("Run",0.3,PlayMode.StopSameLayer);
}
else if(Input.GetKeyUp(KeyCode.Mouse1)){
if(player.GetComponentInChildren(Gathering).rightHandRes != null){
if(player.GetComponentInChildren(Gathering).rightHandRes.isTool == true){
Debug.Log("Has said to do animation ");
animation.CrossFade("Stab",0.3,PlayMode.StopSameLayer);
}
}
}
else{
animation.CrossFade("Idle",0.3,PlayMode.StopSameLayer);
}
}
I hope that someone can help me with this problem :)
why not use unity's new animation system $$anonymous$$ecanim?
yeah its about time that I learn thqt, do you know any good tutorials?
$$anonymous$$echanim is nice, but it has flaws, one major flaw is the lack of animation events, it made adding effects so much easier than having to code it into the curve.
@rowdyp I saw a plugin for events in mecanim in the asset store, I haven't used it and don't remember what it is but if thats what you need then I would suggest looking for that as I find $$anonymous$$echanim very powerful.
yes that is right i looked it up but it is 30 dollars :( so i would love to just see what i'm doing wrong in the above question :)
Answer by Dugular7 · Jul 24, 2013 at 06:20 PM
The main problem I see here is that you are essentially calling the idle animation every frame.
Your run animation will work because you are looking for a constant press of the key W, but you are only doing a GetKeyUp for the stab (Which is fine and logical). So what is happening is that on the very next frame, it sees that there is no more GetKeyUp for the mouse button and reverting to the idle.
Therefore, your best bet would be to modify the final else line to say:
else if(!animation.IsPlaying("stab")){
animation.CrossFade("Idle",0.3,PlayMode.StopSameLayer);
}
That way, it won't play idle until the stab animation is completed :) Just make sure the stab animation isn't a looping one!
Except of course you'll need to capitalise the S on stab, which I forgot to do there!
yes! it worked! thank you :) and the capitals dont matter that much because it was just an example because my animations are named in my native language. but thanks for the attention to details
Answer by chris_taylor · Jul 24, 2013 at 05:20 PM
You could use Mecanim. Here is their tutorial for it. Although I think they have more features now that are not shown in this video, but it is still a good starting point.
Edit: I think by using PlayMode.StopSameLayer you are making the crossfade act the same way as just a normal Play
oh i will check that out in a moment sounds as a possible solution. i'll report back.
Your answer
Follow this Question
Related Questions
Idle Animations, Player Walking 0 Answers
Player plays walking animation if I press a and d at the same time while standing still 2 Answers
Animated character making mesh move when idle-animation is playing 1 Answer
What's a good way to do multiple Idle animations? 2 Answers
How can I move between two idle animations for an NPC on a timer? 0 Answers