how can i take time value from timer (Asked again clearly)
I have timer and checkpoints in my game i want to write down moments when player passes this check points i can handle with text things it is easy but i cant write down time when timer still working is it possible i want to give example now time starts and you reach first checkpoint at 00:11:12 and second 00:22:44 third 00:35:32 it will be shown like this
Current Time : 00:35:32 (same with third checpoint 1.Check : 00:11:12 2.Check : 00:22:44 3.Check : 00:35:32
There is part of my timer Script corresponding i search everywhere but couldn't find thanks a lot
if(SceneTestMap.GetComponent<SceneTest_Map>().checkPoint==1)
{
checkPoint.text = TimeToString(?????);
}
this is the whole script
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
public Text timerText;
private float startTime;
public GameObject SceneTestMap;
public Text Hedef_74text;
bool keepTiming;
float timer;
void Start () {
StartTimer();
}
void Update () {
if(SceneTestMap.GetComponent<SceneTest_Map>().IsRaceFinished == true){
Debug.Log("Timer stopped at " + TimeToString(StopTimer()));
}
if(keepTiming){
UpdateTime();
}
if(SceneTestMap.GetComponent<SceneTest_Map>().checkPoint==1)
{
checkPoint.text = TimeToString(?????);
}
}
void UpdateTime(){
timer = Time.time - startTime;
timerText.text = TimeToString(timer);
}
float StopTimer(){
keepTiming = false;
return timer;
}
void ResumeTimer(){
keepTiming = true;
startTime = Time.time-timer;
}
void StartTimer(){
keepTiming = true;
startTime = Time.time;
}
string TimeToString(float t){
string minutes = ((int) t / 60).ToString();
string seconds = (t % 60 ).ToString("f2");
return minutes + ":" + seconds;
}
}
Answer by FortisVenaliter · May 03, 2016 at 08:31 PM
How about:
text = TimeSpan.FromSeconds(timeValue).ToString();
I am taking error about TimeSpan thing not worked Assets/Scripts/Timer.cs(31,45): error CS0103: The name `TimeSpan' does not exist in the current context
actually it is not fixing my problem i couldnt figure out i think it was simple like timer-Time.deltaTime or something like that to stop time just writen on checkpoint text