- Home /
Whole number Mathf.SmoothDamp ?
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);
}
}
}
Answer by Bunny83 · Feb 12, 2018 at 04:05 AM
Uhm you already made an int variable called "toDisplay", However you still use m_SmoothScore in your string that you display. Just use toDisplay instead:
int toDisplay = (int)Mathf.Round(m_smoothScore);
if (toDisplay != m_displayedScore)
{
m_displayedScore = toDisplay;
text.text = "Score: " + toDisplay;
}
Also answered here.
@Rembo4Fight, please don't duplicate questions, be patient, and someone will respond.
Your answer
Follow this Question
Related Questions
How to make a number Whole after SmoothDamp ? 1 Answer
Local Party Game Score Transfer 1 Answer
Mathf.Smoothdamp, need help troubleshooting! 0 Answers
Mathf.SmoothDamp freeking out? 0 Answers
Time goes wrong in the Build 1 Answer