- Home /
Question by
KUFgoddess · Feb 18, 2018 at 07:21 PM ·
triggertimer2d-gameplay
How to add 5 seconds to Timer that is counting DOWN OnTriggerEnter2d?
how can i add 5 seconds to my timer on triggerenter 2D
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Timer : MonoBehaviour {
// Use this for initialization
void Start()
{
//restartMenu.SetActive(false);
}
// Update is called once per frame
void Update()
{
timeLeft -= Time.deltaTime; // so basically this is subtracting float - TIME
timerText.text = "TimeLeft:" + Mathf.Floor(timeLeft / 60).ToString("00");
string minSec = string.Format("{0}:{1:00}", (int)timeLeft / 60, (int)timeLeft % 60); timerText.text = minSec;
if (timeLeft <= 0)
{
timeLeft = 0f;
enemySpawner.enabled = false; // So im turning off the enemy spawning when the timer reaches zero
}
}
public float timeLeft = 60f;
public Text timerText;
public InfinitePlatformGenerator enemySpawner;
}
Comment
Best Answer
Answer by JimmyCushnie · Feb 18, 2018 at 07:26 PM
private void OnTriggerEnter2D()
{
timeLeft += 5;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612152903im_/https://answers.unity.com/themes/thub/images/avi.jpg)