So I have a script with a “public Text timer”
and I placed the Text into the box of the script, I play normally but when I load new scene the UI that I put in the box disappeared
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public static GameController data;
public int health;
public Text timer;
public float timervariable;
void Awake ()
{
if (data == null)
{
DontDestroyOnLoad(gameObject);
data = this;
}
else if (data != this)
{
Destroy(gameObject);
}
}
void Start()
{
timervariable = 0;
timer.text = "Time: " + timervariable;
}
void FixedUpdate()
{
timervariable += Time.deltaTime; //Time.deltaTime is time
timer.text = "Time: " + (int)timervariable; //force timervariable to be an integer
}
}