- Home /
 
The question is answered, right answer was accepted
Can't display my Countdown timer text on my end menu. (newbie needing help)
"The component with the Text I need"
using UnityEngine.UI; using System.Collections; using UnityEngine; using UnityEngine.SceneManagement;
public class Countdwn : MonoBehaviour {
 public float cntTime = 300f;
 public float seconds, minutes;
 public Text timeText;
 // Use this for initialization
 void Start()
 {
     timeText = GetComponent<Text>();
 }
 void Update()
 { cntTime -= Time.deltaTime;
     minutes = (int)(cntTime / 60f);
     seconds = (int)(cntTime % 60f);
     timeText.text = minutes.ToString("0") + "." + seconds.ToString("00");
     print(cntTime);
     if (cntTime < 0)
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }
 }
 
               "The End Game Display Text"
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class FinalScore : MonoBehaviour { public float cntTime; public Text timeText;
 public void Start()
 {
     timeText.GetComponent<Countdwn>
 }
 void Update
 {
     get 
         (cntTime).Text 
 }
 
               }
Essentially what Im trying to do : I have a countdown timer in-game thats runs down to 0 and then restarts my game. This timer also displays its time as a Text to make it visible in-game. I want the same time to display on a separate text. Letting the player know what time they finished at. I apologize if this is confusing as for I'm very green to this and I truly appreciate the help ahead of time.
Do you want the text to stay even after the scene restarted?
Answer by Mahunreah · Apr 21, 2018 at 10:38 PM
Hey =)
I'm still a beginner, too, so maybe this won't be too helpful.
If you declare your variables as public, you can set them inside the inspector. This means: In this case, you don't need to write something in your Start ()-function. Just drag and drop the text-field in the hirarchy into the corresponding "text"-field inside your inspector's view of your gameObject. I think that should help with your script not finding the needed text-field.
Furthermore, I think you are missing some ; at the end of your lines in your second script.