Hi, I’m working on a game and I want to be able to increase the difficulty (speed) of the game depending on how long someone has been playing for… I can’t use the Real time since startup, because I want it from the moment they push “Start Game” rather than have the timer start as the whole game loads up… And I’d also like the timer to pause between levels…
Is there an easy way to do this? (I know only basic Javascript right now…) Say every 5 minutes of gametime, the game will run 10% faster, if someone could help me out, I’d greatly appreciate it.
here, I had an example to start the timer with UI button. I create a function to pause the timer too.
this function “stopTimer()” you can call to pause the timer. Hope this script can solve your problem.****
This is my code…
Drag the script to the main camera - make sure unchecked the script
add object (main camera) to the button click there, select the function toggletimer.enabled.
if you want to pause your timer, call “stop timer function.”
if you want for details, you can watch my video. All important steps are zoom, below is my script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class toggleTimer : MonoBehaviour {
float timer = 0;
public Text timerText = null;
int intTimer = 0;
int Counter = 0;
int ifstopTime =0;
int currentTime =0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
timer += Time.deltaTime;
if (ifstopTime == 0) {
changeText ();
} else {
timerText.text = "pause";
}
}
public void changeText()
{
intTimer = (int)timer + currentTime;
timerText.text = intTimer.ToString ();
}
public void stopTimer()
{
Counter++;
if (Counter % 2 == 0) {
ifstopTime = 1;
} else {
ifstopTime = 0;
}
currentTime = intTimer;
timer = 0;
}
}