Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

[RESOLVIDO] MissingComponentException: There is no 'GameObject' attached...

Olá! Estou criando o jogo dos zumbis e me deparei com o seguinte erro:

MissingComponentException: There is no 'GameObject' attached to the "Zumbi" game object, but a script is trying to access it.

Vi que já existiu uma discussão sobre esse tema, porém, ao contrário dela, eu já coloquei O jogador usando a interface, arrastando seu gameobject atéo campo da variável.

Aqui está meu código:

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

public class ControlaZumbi : MonoBehaviour
{
    // tg = target
    public GameObject tg;
    // rb = rigidbody
    public Rigidbody rb;

    // Start is called before the first frame update
    void Start(){
        rb = GetComponent<Rigidbody>();
        tg = GetComponent<GameObject>();
    }

    // Update is called once per frame
    void Update(){
    }

    // This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
    void FixedUpdate()
    {
        Vector3 direction = tg.transform.position - rb.position;
          this.rb.AddForce(this.rb.position + direction.normalized);  
    }
}

Pesquisei bastante na internet porem não consegui encontrar ajuda. Agradeço a atenção :)

1 resposta
solução!

Moçada já descobri. Era um bug do próprio Unity. Após reiniciar a Engine tudo voltou ao normal. Ou melhor, 'normal' pois com o código acima meu Zumbi sai voando. Mas o problema desse fórum já foi resolvido.