- Home /
Animator does not play Animation on object
Hi Guys,
My Animation won't play. The animation works fine when I test it on the preview. But it does not work when i try and Play. I have set up a parameter to trigger the animation on the script whenever right key is pressed but don't understand why would not play. Thanks.
using UnityEngine;
using System.Collections;
public class BaseballMove : MonoBehaviour {
public Animator Animator;
public KeyCode J;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if( Input.GetKeyDown(J) )
{
Animator.SetTrigger("Move");
}
}
}
Answer by UnityCoach · Dec 29, 2016 at 11:27 PM
You can't give the name of a Class to a member. We usually use camelCase for members. You also have to assign it, Unity stopped providing quick access properties to sibling components. You can also use a RequireComponent Attribute to make sure there's one attached.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Animator))]
public class BaseballMove : MonoBehaviour {
public Animator animator;
public KeyCode J;
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if( Input.GetKeyDown(J) )
{
animator.SetTrigger("Move");
}
}
}
Your answer
Follow this Question
Related Questions
[Resolved]Animator.Rebind on instantiated child. 0 Answers
Running animation 1 Answer
Playing animation at the start 1 Answer
animation control problem 0 Answers
teleporter not working due to animator 0 Answers