meus obstáculos estão sendo destruídos e não está gerando novos.
`` using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Obstaculo : MonoBehaviour { [SerializeField] private float velocidade = 0.5f; [SerializeField] private float variacaoDaPosicaoY;
private void Awake()
{
this.transform.Translate(Vector3.up* Random.Range(-variacaoDaPosicaoY, variacaoDaPosicaoY ));
}
private void Update()
{
this.transform.Translate(Vector3.left* this.velocidade * Time.deltaTime);
}
private void OnTriggerEnter2D(Collider2D outro)
{
this.Destruir();
}
private void Destruir()
{
GameObject.Destroy(this.gameObject);
}
}
``
está dando esse erro:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) (at :0) UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at :0) UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at :0) GeradorDeObstaculos.Update () (at Assets/Scripts/GeradorDeObstaculos.cs:23)