I am showing double on screen and it disappear
I have a canvas where I am showing a strength points. On every exercise you do your strength gets bigger. But sometimes I am adding to strength value like 0.3777753. After some of this operations my strength points are invsible. I want it to show only numbers with one number after comma. Like 5.6 not like 5.651234. It looks like that:
And after some operations my value disappears
Code of the text changer looks like this; using UnityEngine; using UnityEngine.UI; using System.Collections;
public class siła : MonoBehaviour { public static double sila=1; Text text; // Reference to the Text component.
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> ();
// Reset the score.;
}
void Update ()
{
text.text = "Strength " + sila;
}
} I am increasing strength with this buttons
Answer by SilverSho0t · Aug 22, 2017 at 04:04 PM
The problem is probably because your text box is too small and to have only one decimal number you need to write this :
void Update ()
{
text.text = "Strength " + sila.ToString("F1");
}
Your answer
Follow this Question
Related Questions
How to disable all canvas at the start of a scene 2 Answers
How do I stop this annoying transform from 'snapping'? 1 Answer
I want to input GameObject(has camera component) to Canvas's EventCamera by using Scripts 0 Answers
How to position world space canvas from script 0 Answers
Hide/Unhide Canvas in AR Project 0 Answers