- Home /
Show the int/float value in GUI.Label
Hi!
I have a float, it changes over time. I want to show/write out the value of this float in a GUI.Label. The float is nanometersinglerun. This is the code:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public static float nanometersinglerun = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
nanometersinglerun = Time.timeSinceLevelLoad;
}
void OnGUI () {
GUI.Label (new Rect (50, 25, 100, 30), nanometersinglerun);
}
}
When i try to start, it says: The best overloaded method match for 'UnityEngine.GUI.Label(UnityEngine.Rect, string)' has some invalid argument
and
Argument '#2' cannot convert 'float' expression to type 'string'
Both errors are at (19,17)
When i put the nanometersingletime into '' '', it works, but shows me ''nanometersingletim'' not the value.
Thanks!
Answer by PAEvenson · Jul 15, 2013 at 06:54 PM
use
GUI.Label (new Rect (50, 25, 100, 30), nanometersinglerun.ToString());
or
GUI.Label (new Rect (50, 25, 100, 30), string.Format("{0}", nanometersinglerun);
Alternatively, you can also use ""+nanometersinglerun
Your answer
Follow this Question
Related Questions
Gui label variable as a string.. 1 Answer
GUI LABEL behind viewport rect of mini map? 1 Answer
GUI.DrawTexture Error & Static Variables!! 2 Answers
MultiColor In 1 Label? 2 Answers