- Home /
Question by
AgarFun · Apr 15, 2017 at 11:58 AM ·
c#timertimer countdowntimer-script
CountDownTimer Help
I want to create a CountDownTimer, when my player touch a cube, the score increase of 10 (done) and the DownCountTimer should be start at 60 score and if this < 0 the player is destroy.
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class EatCube : MonoBehaviour { public string Tag; public Text Letters; public float Increase;
float Score = 60f;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == Tag) {
transform.localScale += new Vector3 (Increase, Increase, Increase);
Destroy (other.gameObject);
{
Score += 10;
Letters.text = "SCORE: " + Score;
}
}
}
}
It works !
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Chrono : MonoBehaviour {
public Text Letters;
public float Destroy;
float Score = 60f;
void Update()
{
Score -=Time.deltaTime;
Letters.text = "SCORE: " + Score;
if (Score < 0);
{
Destroy (gameObject);
}
}
}
It doesn't works
Comment
Answer by The-Evster · Apr 15, 2017 at 06:57 PM
public Text Letters;
public float Destroy;
float Score = 60f;
void Update()
{
Score -=Time.deltaTime; <= here is your problem) change it to Score -= 1 * Time.deltaTime;
Letters.text = "SCORE: " + Score;
if (Score < 0);
{
Destroy (gameObject);
}