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 cirus · Nov 04, 2012 at 04:10 PM · updatetimercountdown3dtext

Timer Countdown problem

good evening I would like to make a countdown timer of, and in my onCollision I incremented by 20 seconds. I have done this but it did not work:

         if(hit.gameObject.tag == "HouseCollider"){
         //increment timer
         timer+=60;
         UpdateComponents("time");
     }


And on my UpdateComponents :

         if(component == "time"){
             GameObject.Find("time").guiText.text=""+timer;
         }


I have a 3DText to display my timer : function OnGUI () {

     //60 seconds for begining tests (timer = 60)
    var guiTime = timer - (Time.time - startTime);
    var minutes : int = guiTime / 60;
    var seconds : int = guiTime % 60;
    var fraction : int = (guiTime * 100) % 100;
 
    textTime = String.Format ("{0:00}:{1:00}:{2:000}", minutes, seconds, fraction);
    GameObject.Find("time").guiText.text=""+textTimer


And i don't know why timer didn't increment by 20 seconds .

Comment
Add comment · Show 4
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 Fattie · Nov 04, 2012 at 04:10 PM 0
Share

long explanation of INvokeRepeating() etc at http://unityGE$$anonymous$$S.com. hope it helps!

avatar image XienDev · Nov 04, 2012 at 04:21 PM 0
Share

ok, but where code you add 20 sec to a timer ?

avatar image cirus · Nov 04, 2012 at 06:01 PM 0
Share

I'm sorry that's +60 seconds i have changed it... It's on my first code ...

@Fattie : thanks but it should increment the timer OnTrigerEnter, like this :

function OnTriggerEnter(hit : Collider) {

if(hit.gameObject.tag == "HouseCollider"){ if(gifts > 0){ //increment timer timer+=60; ... }

And it doesen't work ..

avatar image XienDev · Nov 04, 2012 at 06:28 PM 0
Share

check in Debug.Log, if your trigger works right or not... then in 3dText ongui put code where u assign timer from string (text) like: timer = int.TryParse(GameObject.Find("time").guiText.text); ??

And don't forget to check, what is variable timer and how you acces it in first snippet. is it from other script or not.. I can't imagine whole idea how it should work.. going look to forum at unityGE$$anonymous$$S.com

The main thing. Can u post some snippet to make me happy =)))

if i understood u well, i go make my implementation of this thing

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by XienDev · Nov 04, 2012 at 06:44 PM

why First String is textTime in third snipped, and second is textTimer. may be it is your mistake ?

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
avatar image
0

Answer by XienDev · Nov 04, 2012 at 06:56 PM

Ok. I've made my variant in c#.. here is screen

alt text

My Text3dScript.cs

 using UnityEngine;
 using System.Collections;
 
 public class Text3dScript : MonoBehaviour 
 {
     float startTime;
     TextMesh textMesh;
     
     public static float timer = 60;
     
     void Start()
     {
         startTime = Time.time;
         textMesh  = this.gameObject.GetComponent<TextMesh>();
     }
     
     // Update is called once per frame
     void Update () {
         
         float guiTime = timer - (Time.time - startTime);
         if (guiTime > 0)
         {
             int minutes = (int)(guiTime / 60);
             int seconds  = (int)(guiTime % 60);
             int fraction = (int)((guiTime * 100) % 100);
     
             textMesh.text = string.Format ("{0:00}:{1:00}:{2:000}", minutes, seconds, fraction);    
         }
     }
 }

my TriggerScript is

 using UnityEngine;
 using System.Collections;
 
 public class triggerScript : MonoBehaviour {
 
     void OnTriggerEnter(Collider c)
     {
        Text3dScript.timer += 20;
     }
 }
 

How can you see. All is ok, and works


12.png (282.6 kB)
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

11 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

Related Questions

Timer not work :( 0 Answers

For loop resetting itself, but needs to stop 2 Answers

Countdown timer into text c# 1 Answer

How to restart a level with countdown? 4 Answers

Is an object with an update function possible? (C#) 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