- Home /
How do I make an animation change based on an integers value.
I code in Java with Unity, and I am not very familiar with Java quite yet. I am also fairly new to Unity, but the goal I am looking to accomplish is to have an animated model change its animation based on a value.
Currently its Walk will equal 1, Jog = 2, Run = 3, and I need the value to be able to be input by the player. Nothing fancy, just a rectangle on the screen that can be modified by pressing the number 1, 2 or 3.
Honestly, if anyone can just point out to me where to start, and which functions I would want to use, it would be greatly appreciated.
Answer by Khada · Aug 20, 2012 at 07:49 AM
Something to this effect:
void OnGUI()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
animation.Play("Walk");
}
else if(Input.GetKeyDown(KeyCode.Alpha2))
{
animation.Play("Jog");
}
else if(Input.GetKeyDown(KeyCode.Alpha3))
{
animation.Play("Run");
}
//etc...
}
Answer by schetty · Aug 20, 2012 at 11:53 AM
if(Input.GetKeyDown(KeyCode.Alpha1))
{
animation.crossfade("Walk");
}
else if(Input.GetKeyDown(KeyCode.Alpha2))
{
animation.crossfade("Jog");
}
else if(Input.GetKeyDown(KeyCode.Alpha3))
{
animation.crossfade("Run");
}
Your answer
Follow this Question
Related Questions
Animation Keeps Looping 2 Answers
How do I control animation with a value? 1 Answer
Zombie attack script animation help! 0 Answers
How to animate a color value? 1 Answer
Animation is not running, but value is stuck, if Animatori s enabled! 0 Answers