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
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.