Errors on creating Animation Script controller.

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyController : MonoBehaviour {

    private GameObject player;
    NavMeshAgent agent;

    public float tempoParaTeleport;
    bool podeTeleportar;
    public GameObject gameC;
    private Animator anim;
    public bool estaTomandoDano;

    private GameObject canvas;

    void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        agent = this.gameObject.GetComponent<NavMeshAgent>();
        podeTeleportar = true;
        anim = GetComponentInChildren<Animator>();

        canvas = GameObject.Find("Canvas");

        estaTomandoDano = false;
    }

    public void ChasePlayer()
    {
        Transform aux = player.GetComponent<Transform>();
        float dist = Vector3.Distance(aux.position, transform.position);

        if (dist <= 3.0f)
        {
            agent.enabled = false;
            anim.SetInteger("estado", 1);
        }
        else {
            agent.enabled = true;
            anim.SetInteger("estado", 1);
            agent.destination = player.transform.position;
        }
    }
       

    void Update()
    {
        Transform aux = player.GetComponent<Transform>();
        float dist = Vector3.Distance(aux.position, transform.position);

        if(dist >= 60.3f )
        {
            Teleportar();
            estaTomandoDano = false;
        }

        else if(dist <= 30.0f)
        {
            ChasePlayer();
            estaTomandoDano = false;
        }

        if(dist <= 7.0f)
        {
            gameC.gameObject.GetComponent<GameController>().TomarDanoInimigo();
            anim.SetInteger("estado", 2);
            estaTomandoDano = true;
        }

        PararDeAtacar();

        if(estaTomandoDano)
        {
            canvas.GetComponent<CanvasConfig>().IsDamagedImage();
        }
           else
        {
            canvas.GetComponent<CanvasConfig>().IsNotDamagedImage();
        }

        Debug.Log("Esta tomando dano:"+estaTomandoDano.ToString());

    }

    IEnumerator CoolDownTeleport()
    {
        yield return new WaitForSeconds(tempoParaTeleport);
        podeTeleportar = true;

    }

    public void Teleportar()
    {
        if (podeTeleportar)
        {
            podeTeleportar = false;
            this.gameObject.transform.position = new Vector3(player.transform.position.x - 10,
                0f,
                player.transform.position.z - 10);//setar a position para proximo do player0
            anim.SetInteger("estado", 0);
        }

        else
        {
            StartCoroutine(CoolDownTeleport());
            anim.SetInteger("estado", 0);
        }


    }

    void PararDeAtacar()
    {
        if (gameC.GetComponent<GameController>().vida <= 0)
        {
            anim.SetInteger("estado", 0);
        }
    }
       
}

Errors:

NullReferenceException: Object reference not set to an instance of an object
EnemyController.PararDeAtacar () (at Assets/Scripts/EnemyController.cs:117)
EnemyController.Update () (at Assets/Scripts/EnemyController.cs:73)

“SetDestination” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:set_destination(Vector3)
EnemyController:ChasePlayer() (at Assets/Scripts/EnemyController.cs:44)
EnemyController:Update() (at Assets/Scripts/EnemyController.cs:62)

If someone could help me…

“gameC” object doesn’t have an instance at the time when this error happens. Maybe you forgot to reference it in the inspector or you set it to null at some point?

Either that or it doesn’t have the “GameController” component on itself.

It can be either one of these.