Hello my fellow Unities! I’m making a 2D mobile survival game, where I have a timer counting upwards that is printed on the screen. I also have a power up, that is used to slow down the enemies and everything around them. Now I have a problem, is it possible to make the timer ignore the Time.Timescale while the power up is in use?
How would I go forward in solving this?
Here’s the code for the timer:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TimerScript : MonoBehaviour
{
//Create timer
public static float timer = 0f;
//Create displayed timer
Text text;
void Awake()
{
//Load Text class
text = GetComponent<Text> ();
//Reset the timer
timer = 0f;
}
void Update()
{
//Start the timer and keep it going
timer += Time.deltaTime;
//Write out the timer on the screen
text.text = "" + timer.ToString("F1");
}
}
And here’s the code for the power up and when it’s in use:
void OnTriggerEnter2D(Collider2D col)
{
if(col.gameObject.tag == "PowerUp1")
{
if(Time.timeScale == 1.0f)
{
Time.timeScale = 0.2f;
Destroy(GameObject.FindGameObjectWithTag("PowerUp1"));
}
}
}