- Home /
gui text is absent in Unity 4.6
I follow this Roll a ball tutorial. According to it, I need to add Gui Text to show score. But it's absent in Unity 4.6. Should I add Text from UI instead?
If I try this I get error:
MissingComponentException: There is no 'RectTransform' attached to the "Display Text" game object, but a script is trying to access it.
And I don't see any labels in UI. What object should I add instead Gui Text?
Yes try the UI as you thought, yet to try myself but from what I have read this is the way to go :)
not sure how to use it. Can I just add Text? Or I need add Panel first?
Really don't know yet, not upgraded, sorry :S
Will publish for you, you should get someone who knows about it and is able to give you a proper answer :)
Answer by Eric5h5 · Dec 13, 2014 at 04:32 AM
GUIText is not absent in 4.6. You can add the GUIText component as usual; it's in the same component menu where it's always been. It's only the GameObject+GUIText creation shortcut that is gone.
Totally true. But unless you really need the legacy functionality, I would strongly suggest taking the time to learn the new tools. Especially if you are just starting out and have no previous knowledge of the old way.
don't see GUIText in menu. But anyway going to use Text ins$$anonymous$$d.
It's in the component menu, as I said. Where it's always been. The component menu. Not the gameobject menu. Component.
okay, I did as in the next answer: Create a new empty game object, then click on "add component" in the Inspector window and then type "GUIText" in the search box.
Now I see it.
Answer by Kiwasi · Dec 13, 2014 at 01:55 AM
Got irritated enough to redo the video, enjoy.
Original Answer
I have a bunch of tutorials in my profile that should show you the basics of working with UI Text. There is also a tutorial in the learn section on UI Text.
Couple of things to note
Add using UnityEngine.UI at the top of your script
Create a Text using the Create -> UI menu. This will automatically add the other GameObjects the UI system needs. (Canvas and EventSystem).
Change the public variable from GUIText to Text
Modify it with the .text property
okay, added public Text Score in class PlayerController, then Score.text = "Score" + count.ToString() to Start(); get NullReferenceException: Object reference not set to an instance of an object Did I miss something?
Did you assign Score via the inspector? This is a common cause of a null reference exception.
Also note that convention is to use capitalise ClassNames and use camel case for variableNames. It will make it easier for you to read others code and have others read your code if you follow this convention.
Score should be assigned to the UI Text component that you created. Just drag the UI GameObject from the heirachy across to the Score space in the inspector.
Answer by screenname_taken · Dec 13, 2014 at 11:02 PM
Create a new empty game object, then click on "add component" in the Inspector window and then type "GUIText" in the search box. The older gui is hardly legacy, the new one is built on top of it. If you want something to just show a counter on the top of the screen, i'd go with that instead of making a canvas, adding stuff to it all just to show that.
The old GUI is very much legacy, and the new GUI has nothing whatsoever to do with it. You can check the UI code if you want (the source is available), to see for yourself.
Nor sure weather to vote you up for providing explicit, easy to follow instructions, or down for saying there is a relationship between GUIText and the UI.
Did they say in one of their tutorials/videos that the system won't be abandoned as it's useful to have a "direct" route? Honestly i heard them saying "it's built on it". Unless they were meaning more something like expanding.
No, they never said "it's built on it" or anything close to it; I'm afraid you misunderstood somehow. I've never seen them say GUIText won't be abandoned, and I wouldn't be surprised if it was removed at some point. I can't see how it's really any more "direct" than UI Text.
Your answer
