Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Derek 1 · Apr 07, 2011 at 07:05 PM · timerlerpz

Countdown Timer location

Thanks to the code provided by Phuzzy on the forums, I finally figured out how to create a countdown timer in my game and have it linked to GuiText. However, I am having a problem getting the GuiText to appear where I want it to. I am really new to programming and have only been working with the Lerpz demo so far so I tried to add the code from the StartMenu into the countdown timer that deals with the postion of the title of the game. This of course did not work. I have also tried using the Anchor and Alignment settings in the GUIText, but it is not working. Also, I used the Pixel Offset to get the GUItext at the top of the screen in Unity, but when I go into the webplayer, the timer is missing. I want the code at the top of the screen and centered no matter what the screen size is. Right now, it is centered, but it is sitting right in the middle of the screen. What do I need to do to get it at the top?

Here is the full code for the timer:

//countdownTimer: methods to handle a countdown timer //it is always assumed that there is a guiText item available for the display output

//PRIVATE MEMBERS private var b_timer_active : boolean; //switch to start/stop timer private var f_timer_done; //method to be called when timer runs down private var fl_start_time : float; //start time (in seconds) private var fl_time_left : float; //time left (in seconds)

//PUBLIC METHODS function getFlRemainingTime() { //get the time remaining on the clock return fl_time_left; }

function setTimerDoneAction(f_method_fp) { //set the method to be called when the timer is done f_timer_done = f_method_fp; }

function setTimerState(b_active_fp : boolean) { //set the active state of the timer b_timer_active = b_active_fp; }

function setStartTime(fl_time_fp : float) { //set the starting value for the countdown fl_start_time = fl_time_fp; }

function Update() { if (b_timer_active) { //check to see if the timer is "on" if (!guiText) { //check for an available GUIText component Debug.Log("countdownTimer needs a GUIText component!"); enabled = false; return; } else { doCountdown(); //decrement the time and send value to GUIText for output } } }

//PRIVATE METHODS private function doCountdown() { // if (fl_start_time && b_timer_active) { //make sure that we had a starting time value before conting down fl_time_left = (fl_start_time - Time.timeSinceLevelLoad); fl_time_left = Mathf.Max(0, fl_time_left); //don't let the time fall below 0.0 guiText.text = outReadableTime(fl_time_left); //display the time to the GUI if (fl_time_left == 0.0) { //if time has run out, deactivate the timer and call the followup method b_timer_active = false; if (f_timer_done) { //only call the followup method if we had one f_timer_done(); } } } else { Debug.Log("countdownTimer needs a value set for fl_time_left"); } }

private function outReadableTime(fl_time_fp : float) { //format the floating point seconds to M:S var i_minutes : int; var i_seconds : int; var i_time : int; var s_timetext : String; i_time = fl_time_fp; i_minutes = i_time / 60; i_seconds = i_time % 60; s_timetext = i_minutes.ToString() + ":"; s_timetext = s_timetext + i_seconds.ToString("D2"); return s_timetext; }

Does something need to be added to it that I am missing? Thanks for any help you can provide!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DaveA · Apr 07, 2011 at 08:37 PM

Check the position of the object containing the GUI text itself. Z=0, x = .5, y = .9 (or .1 I forget)

Comment
Add comment · Show 1 · 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 Derek 1 · Apr 07, 2011 at 11:41 PM 0
Share

I got it working! I had to add transform.position.x =.5; transform.position.y=.99; to the Function Update() section and the countdown timer works just fine. Thanks for the help!

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Getting an object to spawn on a set time 1 Answer

On Lerpz game making shooting monster 1 Answer

How do I...? [scripting help] 2 Answers

two different collider in one script 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