Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

NullReferenceException: Object reference not set to an instance of an object

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.List1[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;
}

}

2 respostas
solução!

Oi, Brunno, tudo bem?

Esse erro parece interno da Unity, ele deve ficar aparecendo até você não reiniciar a Unity.

Era isso mesmo. Quando abri novamente o projeto ele parou de reclamar hehehe obrigado

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software