Hi I have made an animation and have set it to play on if (Input.GetButtonDown(“Fire1”))
{
but I cannot run the game because of the error BCE0020: An instance of type ‘UnityEngine.Animator’ is required to access non static member ‘Play’. this is the code where I say Animator.Play function Update() { if (Input.GetButtonDown("Fire1")) { Animator.Play("Attack"); var hit : RaycastHit; if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) {
Thankyou in advance for any help.
have a good day
retrieve the animator component first before using it, like:
Animator anim;
void Start(){
anim = GetCompontent/<Animator/>(); //remove the "/", forum problem
}
void Update(){
if (Input.GetButtonDown("Fire1") && anim){
anim.Play("Attack");
}
}