Question by
ClldMeFinn · Dec 17, 2020 at 02:04 PM ·
c#unity 2dtimer
Editable Timer
so i want to make editable timer, but i didnt know the code
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class timer : MonoBehaviour {
Text text;
float day;
public float speed = 1;
// Start is called before the first frame update
void Start() {
text = GetComponent<Text>();
}
// Update is called once per frame
void Update() {
float dayNormalized = day % 1f;
float hoursPerDay = 17f;
float minutesPerHour = 60f;
day += Time.deltaTime * speed;
string hourString = Mathf.Floor(dayNormalized * hoursPerDay).ToString("00");
string minuteString = Mathf.Floor((dayNormalized * hoursPerDay) % 1f * minutesPerHour).ToString("00");
text.text = hourString + ":" + minuteString;
}
}
this is my code, but when i enter the playmode. the timer always start from 00:00 and i didnt know how to make it editable, can anyone help me? Peace
Comment
what do you mean by editable? the user can click an input field opens and you are able to enter the current time?