- Home /
Animation Variable Not Assigned?
Hello, I am trying to get one animation to play using mechanim so I made a trigger named Shoot and added it to the transition from anystate. I get an error saying that I need to assign the anim variable of the PlayerAnimator script in the inspector. But, when I go to the scrip in the inspector there is no variable slot for the anim. Here is my code, I followed a Unity tutorial.
using UnityEngine;
using System.Collections;
public class PlayerAnimator : MonoBehaviour {
Animator anim;
int shoot = Animator.StringToHash("Shoot");
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
}
public void Shoot()
{
anim.SetTrigger (shoot);
}
}
Answer by Effervescence · Aug 21, 2016 at 06:13 AM
Remember, only public variables are visible in the inspector. Set anim to public if you want to set it in the inspector.
Looking at your Start() method, it seems like you should have an animator component attached to the same gameobject that your script is attached to. Make sure it is there.
It is still now working. Do you need to add something to the script or do something differently if the player is spawned in?