Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by deenooo · Oct 13, 2013 at 04:31 PM · timercountercountdown

How to add a counter on screen!

I've created this script in javascript. var endTime : float; var textMesh : TextMesh;

 function Start()
 {
 endTime = Time.time + 60;
 textMesh = GameObject.Find ("Timer").GetComponent(TextMesh);
 textMesh.text = "60";
 }
  
 function Update()
 {
 var timeLeft : int = endTime - Time.time;
 if (timeLeft < 0) timeLeft = 0;
 textMesh.text = timeLeft.ToString();
 }

Would i need to add a guitext and change some code?

Comment
Add comment · Show 1
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 Crystalline · Oct 13, 2013 at 04:40 PM 0
Share

Yep, you can either create one with OnGUI function, or just create one in the editor.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Brum · Oct 13, 2013 at 04:40 PM

If you want just simple plain text you could just use the OnGUI method:

http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html

Comment
Add comment · Show 3 · 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
avatar image deenooo · Oct 13, 2013 at 06:32 PM 0
Share

the OnGUI method issn't working D:

avatar image Brum · Oct 13, 2013 at 06:40 PM 0
Share

can you give some more insight of what you'r doing?

avatar image deenooo · Oct 13, 2013 at 06:46 PM 0
Share

The code i've created above is used as a countdown for a game i am making but i've tryed assigning it to a GUIText but that won't work, neither will calling the GUIFunction

avatar image
0

Answer by Cherno · Oct 13, 2013 at 08:47 PM

 var Counter : float;
 
 function Update()
 {
     Counter += Time.deltaTime;
 }
 
 function OnGUI()
 {
     GUI.Label (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100), Counter + "");
 
 }
 
 
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

countdown/countup timer 1 Answer

C# countdown timer 9 Answers

How to stop a countdown from counting down 1 Answer

Countdown timer into text c# 1 Answer

How to restart a level with countdown? 4 Answers


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