GUI Text not showing up :(
Hi everyone,
I'm a huge newbie to coding! I was following the Scroller Shooter Tutorial and making tweaks to the code to make it work for my purposes. I'm trying to add the score to the top right corner. However the GUI text refuses to show up! I have made an empty game object, added the GUI text component, made sure it was on the UI layer, checked it wasn't behind other objects on the z axis... idk I tried everything I could possibly think of and it's still not showing up in Game mode or Scene mode.
I have gotten it to work before, but this is a different save file of the game and for some reason it refuses to render just on this file!! I'm not sure if it's something I've done in my camera settings or something.
I am an artist not a coder, and I am just making a quick demo of my assets to try and get a coder partner for a future project, so I don't have extensive coding knowledge but if anyone has any idea what might be causing this please let me know!!
Thanks in advance!
Answer by gorgiaunity · Jan 14, 2018 at 08:23 PM
@taymakes there's a very simple way to solve it. You have to Add GUI Layer component to the Main Camera object, click on AddComponent>Renderering>GUILayer. If it won't work anyway, try creating an Empity Child for the Main Camera - by the Create menù in the Hierarchy folder - add the GUI Layer component to the new object and set its properties as Main Camera's. I hope it'll help you :)
Answer by rctacbad · Feb 28, 2018 at 06:11 PM
I had the same problem when i tried the tutorial. Since GUIText is already deprecated, I used the Text gameObject instead. To create one select Create > UI > Text in the Hierarchy View. The usage is the same except you have to use the "Text" type when scripting (e.g. public Text scoreText;).
Thankfully, I already finished the Roll-a-ball tutorial where the Text gameObject was used and explained in the "Displaying the Score and Text" assignment.
Answer by onur84 · Jan 18, 2019 at 12:55 AM
I have experienced a similar problem which might be relevant.
When I changed a child object (text changed to "Best Fit) my canvas became invisible.
After a long time of investigation I have found where was the problem; at the most simple place that I have not looked at:
Canvas's scale was set to x=0 y=0 z=0 automaticly. I set all of them to 1 and it is done.
I know that is a very stupid thing but please check this before changing a lot of prefabs, settings and scripts.
Answer by RecyclingBen · May 03, 2017 at 11:43 AM
Is your text a child of a canvas object? If it isn't right click and go to UI>Canvas and parent it to your UI text.
Hopefully this is your problem, but if it isn't then could you give us a screenshot of what your hierarchy looks like?
i have the same problem and did everything u said. what should i do?
Answer by SCoallier · Sep 20, 2017 at 10:33 PM
@taymakes I had this problem...what worked for me was attaching the GUIText object to a new, empty object as you have done and making sure that empty object had a zeroed-out Transform.
Also keep in mind that the X and Y values for a GUIText object are in screen space, not Unity space, and the range for them is 0 to 1 - so X=.5, Y=.5 is the middle of the screen. You can use the Pixel Offset coordinates to make finer adjustments.