Estou tendo a mensagem de "NullReferenceException: Object reference not set to an instance of an object" porém tudo parece funcionar normal, os zumbis reconhecem o jogador e o seguem para atacar. O Jogador está com a tag "Jogador" no Unity. Já tentei apertar o clear no console e reiniciar várias vezes, porém sempre recebo o mesmo erro, apesar de tudo parecer funcionando.
Segue o erro completo:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at :0)
UnityEditor.Graphs.Graph.DoWakeUpEdges (System.Collections.Generic.List1[T] inEdges, System.Collections.Generic.List
1[T] ok, System.Collections.Generic.List`1[T] error, System.Boolean inEdgesUsedToBeValid) (at :0)
UnityEditor.Graphs.Graph.WakeUpEdges (System.Boolean clearSlotEdges) (at :0)
UnityEditor.Graphs.Graph.WakeUp (System.Boolean force) (at :0)
UnityEditor.Graphs.Graph.WakeUp () (at :0)
UnityEditor.Graphs.Graph.OnEnable () (at :0)
Código do ControlaInimigo:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ControlaZumbi : MonoBehaviour {
public GameObject Jogador;
public float velocidade = 5;
void Start()
{
Jogador = GameObject.FindWithTag("Jogador");
int modificadorZumbi = Random.Range(1, 27);
transform.GetChild(modificadorZumbi).gameObject.SetActive(true);
}
void FixedUpdate()
{
//Calcula distancia
float distancia = Vector3.Distance(transform.position, Jogador.transform.position);
//Pega posicao do jogador em relação a posição do zumbi
Vector3 direcao = Jogador.transform.position - transform.position;
//Faz a rotacao do zumbi para olhar pro jogador
Quaternion novaRotacao = Quaternion.LookRotation(direcao);
GetComponent<Rigidbody>().MoveRotation(novaRotacao);
if (distancia > 2.5)
{
//Faz o zumbi andar
GetComponent<Rigidbody>().velocity = direcao.normalized * velocidade;
GetComponent<Animator>().SetBool("Atacando", false);
} else
{
GetComponent<Animator>().SetBool("Atacando", true);
}
}
void AtacaJogador()
{
Time.timeScale = 0;
Jogador.GetComponent<ControlaJogador>().TextoGameOver.SetActive(true);
Jogador.GetComponent<ControlaJogador>().Vivo = false;
}
}