- Home /
Question by
kidakadi · Oct 06, 2017 at 11:55 AM ·
countdowngameobject.tag
how to activate countdown on first Gameobject with tag it being shoot
Hi i wanna start a countdown timer when it have hit my first gameobject, but nomatter what i try i cant get it too work my code look like this
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //Very important!!!
public class CountdownTimer : MonoBehaviour {
private float timerstart, timeElapsed;
public Text timerText;
public int Minutes = 0;
public int Secounds = 0;
private float timeleft;
//public int items; kan bruges til Enemies left
//private int itemsRemaining; bruges til enemy left
// Use this for initialization
void Start ()
{
timerText = GetComponent<Text>();
timeleft = GetInitialTime();
//Hvormanger fjerner er der tilbage
//GameObject[] items = GameObject.FindGameObjectsWithTag("Enemy");
//itemsRemaining = items.Length;
}
// Update is called once per frame
void Update()
{
if (enemyDestroy == gameObject.tag"Enemy")
{
//Update Countdown Cloak
timeleft -= Time.deltaTime;
Minutes = GetLeftMinutes();
Secounds = GetLeftSeconds();
}
//Show Current Clock
if (timeleft > 0f)
{
timerText.text = "Time : " + Minutes + ":" + Secounds.ToString("00");
}
else
{
//Countdown clock has finished
timerText.text = "Time : 0:00";
}
}
private float GetInitialTime() { return Minutes * 60f + Secounds; }
private int GetLeftMinutes()
{
return Mathf.FloorToInt(timeleft / 60f);
}
private int GetLeftSeconds()
{
return Mathf.FloorToInt(timeleft % 60f);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612140411im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
CountDown Timer Help (Seconds problem) 2 Answers
Start countdown timer on a button press 2 Answers
CountDown Camera problem 0 Answers
How to make timer activated after 321 go, no at the same time? 0 Answers
countdown timer 0 Answers