Create Timer, Countdown
Select GUI
Select GUI to show countdown, timer.
Select Timer, Countdown GUI
You can adjust gui properties here
![timer_step-2](/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftimer_step-2.e20b5eff.png&w=640&q=75)
Code
If you want to start the timer, you can use setInterval()
.
timer
let count = 0;
const countboard = GUI.getObject("startBD");
function Start() {
const startCount = setInterval(() => {
count++;
countboard.setText(count, true);
}, 1000);
}
If you want to stop the timer, you can use clearInterval()
.
timer
let count = 0;
const countboard = GUI.getObject("startBD");
function Start() {
const startCount = setInterval(() => {
count++;
countboard.setText(count, true);
if (count >= 10) {
clearInterval(startCount);
}
}, 1000);
}
Here you can use REDBRICK timer to achive similar results.
timer
let count = 0;
const countboard = GUI.getObject("startBD")
const timer = new REDBRICK.Timer();
function Start() {
countboard.setText(count, true);
timer.start();
}
function Update(dt){
count = Math.floor( timer.getTime() );
countboard.setText( count ,true);
}
You can find information about “REDBRICK.Timer” here.
timer
let count = 0;
const countboard = GUI.getObject("startBD")
const timer = new REDBRICK.Timer();
function Start() {
countboard.setText(count, true);
timer.start();
}
function Update(dt){
count = Math.floor( timer.getTime() );
if (count >= 10){
timer.pause();
}
countboard.setText( count ,true);
}
Result