- Home /
Question by
unity_zkpPDaeiSVcO_g · Jul 14, 2019 at 07:54 AM ·
mathfnumbers
Mathf.Round isn't working.
I have this script here:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Score : MonoBehaviour { public Text score; public Text highScore;
public float scoreCount;
public float highScoreCount;
public float pointsPerSecond;
private void Start()
{
score = GameObject.Find("Score").GetComponent<Text>();
highScore = GameObject.Find("HighScore").GetComponent<Text>();
highScore.text = PlayerPrefs.GetFloat("HighScore", 0f).ToString();
}
private void Update()
{
scoreCount += pointsPerSecond * Time.deltaTime;
score.text = scoreCount + Mathf.Round(scoreCount).ToString();
PlayerPrefs.SetFloat("HighScore", scoreCount);
//scoreCount += pointsPerSecond * Time.deltaTime;
//scoreText.text = "Score: " + Mathf.Round (scoreCount);
}
public void MakeHighScore()
{
highScore.text = PlayerPrefs.GetFloat("HighScore", 0).ToString();
}
}
I have been trying for ages to get it to work and now all that's left is for the score to be rounded. Can someone please help me figure out why it won't round "scoreCount"?
Comment
Answer by Hellium · Jul 14, 2019 at 08:23 AM
Mathf.Round works perfectly fine. I believe you want to do:
score.text = Mathf.Round(scoreCount).ToString();
PlayerPrefs.SetFloat("HighScore", Mathf.Round(scoreCount));
Your answer
Follow this Question
Related Questions
Periodic fraction gets converted to int 1 Answer
Mathf.Approximatley if statement 0 Answers
Mathf clamp movement to Camera space in js 1 Answer
How to get a value between 0 and 1 2 Answers
A math issue. 3 Answers