- Home /
Play Different Animation Using the Same Key Press?
I have been trying to figure out a solution to this for hours but just cannot. I want to be able to play a different animation using the same key press.
heres what Im doing so far, if the player is holding down the Up key then play the default animation.
heres what I want to do, if the player collides with this object then disable the default animation, if the player is holding the up key play the new animation.
I am using two different scripts, one for movements and one for collision. The movement script has the default animation inside of it and the collision script has the new animation in it.
I thought for sure it would work if I stop the default animation on collision and then putting, if user holds up key play new animation, but it didnt.
I have also tried combining the two but no luck.
We need a animation.Disable and animation.Enable function or something like it. I could of just put this in my script,
if the user collides with this object then animation.disable("DefaultAnimation"); animation.enable("NewAnimation"); if user holds up key play new animation. Or something like that.
so how to play different animation using the same button press?
Anyway any solutions/feedback/help to my problem will be very much appreciated.
anyone who can help me solve this wins a Well-Done Steak, mash potatoes and a Cherry Icee.
EDIT: After making this post I just had to go and submit the idea for a animation.disable and animation.enable function in scripting. so if you think its a good idea vote for it please
IMO this feature would make a lot of things easier and would be extremely useful to have.
Answer by robert_mathew · Jan 02, 2012 at 07:28 AM
Public Animation player_animation;
Public bool p_bool_anima1;
Public bool p_bool_anima2;
Public bool p_bool_anima1 3;
void Update()
{
if( Input.GetButtonDown("Right") && p_bool_anima1 == true)
{
p_bool_anima1 = false;
player_animation.Play("walk");
}
if( Input.GetButtonDown("Right") && p_bool_anima2 == true)
{
p_bool_anima2 = false;
player_animation.Play("sit");
}
if( Input.GetButtonDown("Right") && p_bool_anima3 == true)
{
p_bool_anima3 = false;
player_animation.Play("idle");
}
}
make this bool true where ever you want other bool false where you want any question means ask
hmm im a little confused with this script, how do I make this work with 2 different scripts? I want my default animations to always play, but on collision with an object I want my collision script to disable the default animations in the move script and enable the animations in the collision script?
EDIT: Looks like there is a function similar to the one I was talking about
// Enable the walk cycle animation["Walk"].enabled = true; animation["Walk"].weight = 1.0;
but it still didnt work the way I want it to, the default animation still plays when holding the up key even if I disable it after the collision. for some reason the only way I can change to the new animation is if I completely remove the default animation.
I know what a switch statement is and how to use it, but I still dont understand how to use this code. I dont get how to switch between my 2 scripts.
make the boolean as static and will able to access it from any script
Your answer
Follow this Question
Related Questions
AnimationClip and AnimationState 0 Answers
I have a problem in ex2D animationsprites. 1 Answer
fbx animation to> blender 1 Answer
Need help with Animations 1 Answer
Cloud recognition in Vuforia 0 Answers