NullReferenceException: Object reference not set to an instance of an object Obstaculo.Update () (at Assets/scripts/Obstaculo.cs:36)
o meu código é
using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Obstaculo : MonoBehaviour { [SerializeField] private float velocidade = 0.5f; [SerializeField] private float variacaoDaPosicaoY; private Vector3 posicaoDoAviao; private Pontuacao pontuacao; private bool pontuei;
private void Awake()
{
this.transform.Translate(Vector3.up * UnityEngine.Random.Range(-variacaoDaPosicaoY, variacaoDaPosicaoY));
}
private void Start()
{
this.posicaoDoAviao = GameObject.FindObjectOfType<avião>().transform.position;
this.pontuacao = GameObject.FindObjectOfType<Pontuacao>();
}
private void Update()
{
this.transform.Translate(Vector3.left * this.velocidade * Time.deltaTime);
if (!this.pontuei && this.transform.position.x < this.posicaoDoAviao.x)
{
pontuei = true;
pontuacao.AdicionarPontos();
}
}
private void OnTriggerEnter2D(Collider2D outro)
{
this.Destruir();
}
public void Destruir()
{
GameObject.Destroy(this.gameObject);
}
} alguem poderia me ajudar?: