Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 29, 2018 at 10:59 PM by doctoct for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by doctoct · Apr 21, 2018 at 05:46 PM · scripting problembeginner

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chik3r · Apr 21, 2018 at 10:05 PM 0
Share

Do you want the text to stay even after the scene restarted?

avatar image doctoct · Apr 21, 2018 at 11:55 PM 0
Share

Id like it to dissapear after the scene restarts

1 Reply

  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

149 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is what a parent gameobject can consult or modify components attributes of it desactivated gameobject children 0 Answers

How to set y rotation axis to 90 on 2d project, always, forever 1 Answer

does SetResolution() change the resolution in editor game screen??? 1 Answer

How to use a timer with a button 2 Answers

True and false work weird? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges