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 mrgohut · Oct 10, 2014 at 01:29 PM · timercountdown

Countdown with sec and min

I want to do countdown with minutes and seconds, when i put 360 in my var i want to do from this 6 minutes, 0 seconds and start countdown. Mathf, but i don't know how to do this, can you help me ?

Comment
Add comment · Show 5
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 robertbu · Oct 10, 2014 at 01:30 PM 1
Share

Please post your code.

avatar image mrgohut · Oct 10, 2014 at 01:54 PM 0
Share

For now i have this:

 using UnityEngine;
 using System.Collections;
 
 public class ParticleSystemDestroyer : $$anonymous$$onoBehaviour {
 
     // allows a particle system to exist for a specified duration,
     // then shuts off emission, and waits for all particles to expire
     // before destroying the gameObject
 
     public float Duration;
     //public float maxDuration;
     public bool stopFire;
     public float stopTime;
     public float maxLifetime;
     bool earlyStop = false;
 
     IEnumerator Start()
     {
         var systems = GetComponentsInChildren<ParticleSystem>();
         var fControl = GetComponentInParent<FireControl> ();
 
         // find out the maximum lifetime of any particles in this effect
         foreach (var system in systems) {
             maxLifetime = $$anonymous$$athf.$$anonymous$$ax(system.startLifetime,maxLifetime);
         }
 
         // wait for random duration
 
         stopTime = Time.time + Duration;
 
         fControl.lifeTime = stopTime - Time.time;
         fControl.$$anonymous$$ = ((int)Duration / 60) - 1;
 
         while (Time.time < stopTime || earlyStop)
         {
             yield return null;
         }
         Debug.Log ("stopping "+name);
         stopFire = true;
         transform.audio.volume = 0;
 
         // turn off emission
         foreach (var system in systems) {
             system.enableEmission = false;
         }
         Broadcast$$anonymous$$essage("Extinguish",Send$$anonymous$$essageOptions.DontRequireReceiver);
 
         // wait for any remaining particles to expire
         yield return new WaitForSeconds( maxLifetime );
 
         Destroy ( gameObject );
 
     }
 
     public void Stop()
     {
         // stops the particle system early
         earlyStop = true;
 
     }
 }
avatar image mrgohut · Oct 10, 2014 at 01:54 PM 0
Share

script #2:

 using UnityEngine;
 using System.Collections;
 
 public class FireControl : $$anonymous$$onoBehaviour {
 
     public ParticleSystemDestroyer fire;
 
     [HideInInspector]
     public float lifeTime;
     public int intLifeTime;
 
     public int $$anonymous$$;
     public float sec;
     public int intSec;
     public string $$anonymous$$utes;
     public string seconds;
 
     public bool fireStatus = false;
     public bool fireIsThere = true;
 
     void Start()
     {
         fire = transform.FindChild ("Fire").GetComponent<ParticleSystemDestroyer> ();
     }
 
     void Update()
     {
         if (fireStatus) {
             TimeHandler ();
             lifeTime = lifeTime - Time.deltaTime;
             intLifeTime = (int) lifeTime;
         }
         if (fire.stopFire) {
             lifeTime = 0;
             fireStatus = false;
             fire = null;
             fireIsThere = false;
             this.enabled = false;
         }
     }
 
     void TurnOn ()
     {
         if (!fireStatus && fireIsThere) {
             transform.FindChild("Fire").gameObject.SetActive(true);
             fireStatus = true;
         }
     }
 
     void TimeHandler()
     {
         sec = sec - Time.deltaTime;
         intSec = (int)sec;
         if (sec < 0) {
             $$anonymous$$ -= 1;
             sec = 60;
         }
     }
 }
 

TimeHandler(); in script #2 and

fControl.lifeTime = stopTime - Time.time; fControl.$$anonymous$$ = ((int)Duration / 60) - 1;

in first script

avatar image HarshadK · Oct 10, 2014 at 01:58 PM 0
Share

All we needed was how you handle the conversion in your script. You gave us everything. ;-)

Just for the record, do not post lengthy unwanted scripts. Post the required snippets from the script only.

avatar image mrgohut · Oct 10, 2014 at 02:36 PM 0
Share

Hm yes but hard to pase here only half of it, because i need to connect countdown with #1 script ;s

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mubanga · Oct 10, 2014 at 02:06 PM

 float timer = 360; //Time in floating seconds
 
 void Update () {
     timer -= Time.deltaTime;
 }
 

That should do for the timer, as for the minutes = timer/60 and floor the out come. The seconds = timer - (minutes * 60).

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 Anxo · Oct 10, 2014 at 02:06 PM

To answer your question, I copied your title, put it in google and added the word "Unity" , This was the first link that poped up.

http://answers.unity3d.com/questions/45676/making-a-timer-0000-minutes-and-seconds.html

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

countdown/countup timer 1 Answer

How to stop a Countdown Timer? 1 Answer

Timer script not perfectly working 1 Answer

how to stop countdown timer after move panel ? how to fix this ?,can you tell me how to stop countdown timer after move panel ? how to fix this ? 0 Answers

How can I display the GAME OVER word across the centre of the screen when the when my timer hits zero? 3 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