Hi, I’m having a problem with my score text, I want to make it count the score and adding new score smoothly, I achieved this.
But now I have a problem that I have my score with the numbers after comma.
I don’t need them, how to make it without that numbers after comma?
Thx
Here is the script, maybe I need to make something int ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour {
Animator anim;
public static int score;
private float m_smoothScore;
private float m_smoothScoreVelocity;
private int m_displayedScore = -1;
TextMeshProUGUI text;
public static bool collected;
public float min;
public float max;
public float t;
void Awake()
{
text = GetComponent<TextMeshProUGUI> ();
score = 0;
}
void Start()
{
anim = GetComponent<Animator> ();
collected = false;
}
void Update () {
//smooth score animation
m_smoothScore = Mathf.SmoothDamp(m_smoothScore,(float)score,ref m_smoothScoreVelocity, 0.2f, Mathf.Infinity, Time.deltaTime);
//display the text
int toDisplay = (int)Mathf.Round(m_smoothScore);
if (toDisplay != m_displayedScore)
{
m_displayedScore = toDisplay;
text.text = "Score: " + m_smoothScore;
}
//text.text = score + " PTS";
if (score > 0)
{
anim.SetBool ("Points", true);
}
if (collected == true) {
t = Time.time;
text.fontSize = Mathf.Lerp (min, max, t);
collected = false;
} else {
t = Time.time;
text.fontSize = Mathf.Lerp (max, min, t);
}
}
}