Animator Error

Grettings! i have a problem with this code

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
    public int speed;
    public float jumpV;

    private bool isOnAir=false;
    private bool walking;
    Animator ani;

    void FixedUpdate(){
        float MoveF=Input.GetAxis("Horizontal");
        Moves (MoveF);
        jump ();
        Animating (MoveF);
        Debug.Log (walking);
    }
           
    void jump(){
        if(Input.GetButton("Jump") && isOnAir==false){
            GetComponent<Rigidbody>().AddForce(Vector3.up*jumpV);
            isOnAir=true;
            ani.SetBool("IsJumping",true);
        }
    }
    void OnCollisionStay(Collision collisionInfo){
        if (collisionInfo.gameObject.tag=="Walls") {

        } else {
            isOnAir = false;
        }
    }
    void Moves(float h){
        Vector3 Move = new Vector3 (h, 0, 0);
        GetComponent<Rigidbody> ().MovePosition (transform.position+Move*speed*Time.deltaTime);

    }
    void Animating(float h){
        if (h != 0f) {
            walking = true;
        } else {
            walking=false;
        }
        ani.SetBool ("IsWalking", walking);
    }
}

Im having this error: Assets/Scripts/PlayerController.cs(10,18): warning CS0649: Field PlayerController.ani' is never assigned to, and will always have its default value null’
Help me please!

in c# if you omit “public” the variable is assumed to be “private”. Private variables have to be assigned through scripts since they don’t appear in the inspector.

If you want to assign in the inspector you need to set it to public, if you want to assign it through code you need a

ani = GetComponent<Animator>();

in the start function

1 Like

Thanks for help!