- Home /
Display time on GUIText C#
I have this script and i am getting CS0119, CS1502 and CS1503 errors! CS0119 Expression denotes a type.... CS1502 The best overloaded method..... CS1503 Arguement #1 cannot convert 'object'.....
void Update () {
GetComponent(GUIText).text = Time.time.ToString("0.0");
}
I want to be able to put this script in to any GUIText component without having to look for the object
Thank you
Answer by robertbu · Oct 16, 2013 at 06:05 PM
In C# you want to do:
GetComponent<GUIText>().text = Time.time.ToString("0.0");
Note that the game object provides you a shortcut for guiText like it does for transform, renderer, and others, so you can do:
guiText.text = Time.time.ToString("0.0");
The issue is that the return from type from the form of GetComponent() you used is 'object'. You could also solve this by casting your original GetComponent() call.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to integrate timer into my C# script? 2 Answers
How to create a delay between spawning of tiles. 0 Answers
Timer doesn't count 0 Answers