Iam still new to this stuff but i got an error i just cant understand.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Attack : MonoBehaviour
{
[SerializeField]
private int speed;
[SerializeField]
private GameObject textObj;
private TextMeshPro text;
private int score = 0;
private void Start()
{
text = textObj.GetComponent<TextMeshPro>();
}
private void Update()
{
transform.Translate(new Vector3(0, -1, 1) * Time.deltaTime * speed);
if (transform.position.y < -5)
{
score++;
transform.position = new Vector3(Random.Range(-10, 10), 6, 0);
text.text = "Score: " + score;
}
}
}
Everytime the text on the text Object should change, it throws an error with NullReferenceExeption but i attached the text-object in the inspector to textObj.