I have a tank, that has level. Tank is a prefab. Tank should show his level using TextMeshPro:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class TankEnd : MonoBehaviour
{
GroundSpawner groundSpawner;
public TextMeshProUGUI levelText;
public int level;
void Start()
{
levelText = GameObject.Find("TankEndLevelText").GetComponent<TextMeshProUGUI>();
groundSpawner = GameObject.Find("GroundSpawner").GetComponent<GroundSpawner>();
level = groundSpawner.level;
levelText.text = "Level: " + level;
}
}
But it doesn't changes. I have an error:
NullReferenceException: Object reference not set to an instance of an object TankEnd.Start () (at Assets/Scripts/Tank/TankEnd.cs:23)
How to fix this? I think tank script can't find level text.