- Home /
Displaying Current Level
Hey,
I'm working on a space shooter and I just want to know how to display a simple text at the bottom left of the screen that says "Level: " and then whatever level the player is on. I'm not sure how to do this using javascript because I'm fairly new to it.
Any help is appreciated and the more detail the better.
Thanks
I posted my answer before it was ready. Now it's edited to show the whole trick.
Answer by aldonaletto · Jun 19, 2011 at 12:40 AM
Use Application.loadedLevelName to get the name and use a GUIText to display it.
Create a GUIText in the Hierarchy window, then set its properties as follows:
Position: X=1, Y=0, Z=0
Text: none (clear the "Gui Text" original)
Anchor: lower right
Alignment: right
Adjust also the Font, Size and Style, then create a script like this and assign it to the GUIText:
function Start(){
guiText.text = Application.loadedLevelName;
}
Awesome thank you! Very Helpful
Can I make this into a prefab to put this on all my levels easily?
No problem - I used this several times. Just create a Prefab and assign the GUIText you've prepared like above to it. One more hint: if you want the text in a different color/transparency, set it in the Start function:
function Start(){
guiText.material.color = Color(0.5,0.5,0,0.8);
...