- Home /
Question by
sourna · Aug 29, 2013 at 10:52 PM ·
timerjs-c#public stringswriting to text
how to convert string into numbers in C#
i would like to now if there is a way to convert this code
GetComponent(GUIText).text = parseInt(Time.time).ToString();
USING C#
Do this right.?
GetComponent<GUIText>().text=int.Parse(Time.time.ToString());
Comment
Cast the float (time.time); a = time.time int b = (int) a then b.ToString
GetComponent<GUIText>().text = Time.time.ToString();
Time.time is a float, not an int.
Answer by Matthew012 · Aug 29, 2013 at 11:16 PM
Just do this.
GetComponent(GUIText).text = Time.time.ToString();
or use ToString(#) to format the output to a simple number, depending on OPs needs
right!
But I want use my timer
I just want to integer
my error is CS0030: Cannot convert type string' to int'
Answer by sourna · Sep 02, 2013 at 08:55 PM
hiii
i fiiiiiiind
fiiiiind
:D
Time.time is double
code C# is :
using UnityEngine;
using System.Collections;
public class Timer : MonoBehaviour {
//float startTimer=Time.time;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
double a=Time.time;
int b;
b= (int)a;
GetComponent<GUIText>().text=b.ToString ();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613113233im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Use variabel in other script does not work 2 Answers
Timer question 0 Answers
Timer will not reset properly. 1 Answer