- Home /
Question by
Hobene · Apr 01, 2020 at 05:31 PM ·
score systemdeltatime
Is it possible to get a int value in time that may be changing seconds afterwards?
I am counting score with a deltaTime timer and want to save the end value as an int. ,I want to count score with delta.Time timer. Is it possible to save a "running" int?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ScoreCounter : MonoBehaviour
{
public Text currentScore;
private float secondsCount;
public int finalScore = 0;
public GameObject obstacleSpawner;
void Update()
{
if (obstacleSpawner.GetComponent<ObstacleSpawner>().mängAlgas == true)
{
ScoreWithTime();
if (GetComponent<TreeBehavior>().mängLäbi == true)
{
finalScore = //hmmm
}
}
}
//call this on update
public void ScoreWithTime()
{
//set timer UI
secondsCount += Time.deltaTime;
currentScore.text = "" + (int)secondsCount * 10;
}
}
//if (secondsCount >= 60)
//{
// print("aeg täis");
// obstacleSpawner.GetComponent<ObstacleSpawner>().round2 = true;
Comment
Best Answer
Answer by The_Three_Vs · Apr 01, 2020 at 06:31 PM
You can use finalScore = Mathf.FloorToInt(secondsCount);
to make finalScore the integer of the current time tracked by secondsCount. Is that what you were looking for?
Hope this helps!