Question by
slicky-grease · Jan 03, 2016 at 09:22 AM ·
c#animatoranimator controller
Animations Not Working when Pressing Certain Keys
Hey Guys
I am fairly new to Unity3D and I am loving the program so far, but there is something I need some help with. In the Animator, I have an Idle and a run animation and here is the script I have for them:
using UnityEngine; using System.Collections;
public class Clover : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start()
{
anim = gameObject.GetComponentInChildren<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("right"))
{
anim.SetInteger("AniPar", 1);
}
else
{
anim.SetInteger("AniPar", 0);
}
if (Input.GetKey("left"))
{
anim.SetInteger("AniPar", 1);
}
else
{
anim.SetInteger("AniPar", 0);
}
}
When I play, the character is using the run animation when pressing the left key, but when I press the right key, she's not using her run pose at all. If anyone can help me with this, I would be very grateful.
Comment
It works, thank you so much. But this is set in a integer through and I want to set it as an float. Do I need to just replace the get integer to floats by any-chance?
Answer by vintar · Jan 03, 2016 at 10:31 PM
Try this Update method.
void Update()
{
if (Input.GetKey("right"))
{
anim.SetInteger("AniPar", 1);
}
else if (Input.GetKey("left"))
{
anim.SetInteger("AniPar", 1);
}
else
{
anim.SetInteger("AniPar", 0);
}
}