filmov
tv
How to create a Stopwatch & Timer in Unity (beginners)

Показать описание
In this Unity tutorial I'll show how you can code your own timer under 2 minutes. This video is not difficult to follow and optimized for beginners.
.........................................
Script (make sure that your class name is the same as your script name) :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class Stopwatch : MonoBehaviour {
[SerializeField] private Text timerText;
private float currentTime;
private bool isPaused;
private void Awake() {
isPaused = true;
currentTime = 0f;
}
private void Update() {
if (!isPaused) {
}
TimeSpan time = TimeSpan.FromSeconds(currentTime);
}
public void StartTimer() {
isPaused = false;
}
public void Pause() {
isPaused = true;
}
public void ResetTimer() {
isPaused = true;
currentTime = 0f;
}
}
.........................................
Thanks for watching this quick unity tutorial. Let me know what you want to see Next. Don't forget to like and Subscribe to stay up to day with my videos!
be sure to leave any questions in the comments below.
.........................................
Script (make sure that your class name is the same as your script name) :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class Stopwatch : MonoBehaviour {
[SerializeField] private Text timerText;
private float currentTime;
private bool isPaused;
private void Awake() {
isPaused = true;
currentTime = 0f;
}
private void Update() {
if (!isPaused) {
}
TimeSpan time = TimeSpan.FromSeconds(currentTime);
}
public void StartTimer() {
isPaused = false;
}
public void Pause() {
isPaused = true;
}
public void ResetTimer() {
isPaused = true;
currentTime = 0f;
}
}
.........................................
Thanks for watching this quick unity tutorial. Let me know what you want to see Next. Don't forget to like and Subscribe to stay up to day with my videos!
be sure to leave any questions in the comments below.