3

Cuando trato de ejecutar mi juego me sale el siguiente error:

MissingRefferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.

Aquí esta mi código pero a decir verdad no se porque sucede el problema o a que se deba exactamente el problema.

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

public class DisparoMovimiento : MonoBehaviour {

    public GameObject player;
    private Transform playerTrans;

    private Rigidbody2D DisparoRB;

    public float DisparoSpeed;

    public float bolitalife;


    void Awake(){
        DisparoRB = GetComponent<Rigidbody2D>();
        player = GameObject.FindGameObjectWithTag("Player"); 
        playerTrans = player.transform;
    }
    // Use this for initialization
    void Start () {
        if (playerTrans.localScale.x > 0){
            DisparoRB.velocity = new Vector2(DisparoSpeed, DisparoRB.velocity.y);
            transform.localScale = new Vector3(1, 1, 1);
        }
        else{
            DisparoRB.velocity = new Vector2(-DisparoSpeed, DisparoRB.velocity.y);
            transform.localScale = new Vector3(-1, 1, 1);
        }
    }

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

4
  • ¿En que linea te muestra el error?
    – Jorgesys
    el 30 oct. 2019 a las 19:23
  • @Jorgesys en la linea donde tengo el void update(){}
    – ASASCED
    el 30 oct. 2019 a las 19:35
  • Este problema es por que cuando intenta acceder al gameobject Player no encuentra un objecto. Comprueba si has arrastrado el prefab del objecto a la variable player o has escrito bien el nombre tag en el Find o tienes puesto el tag en el player. El código lo tienes bien pero te falta asignar esa variable. Ya nos dices. ¡Suerte! el 31 oct. 2019 a las 9:21
  • @ASASCED Update() no tiene nada dentro?, si es así, agregalo, saludos!
    – Jorgesys
    el 7 nov. 2019 a las 23:09

1 respuesta 1

2

El problema es que tu gameObject no esta cogiendo bien la referencia, ya sea por haberla modificado o por haber actualizado Unity, prueba a referenciarselo otra vez o a crear el gameobject de nuevo agregandole el mismo script y la referencia. Puede que no veas ningun cambio por que el update esta vacio, prueba a ponerle algo

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.