- Home /
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 ?
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;
}
}
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
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.
Hm yes but hard to pase here only half of it, because i need to connect countdown with #1 script ;s
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).
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
Your answer
Follow this Question
Related Questions
countdown/countup timer 1 Answer
How to stop a Countdown Timer? 1 Answer
Timer script not perfectly working 1 Answer