Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by fatmanspineapple · Jan 15, 2015 at 12:05 PM · c#unity 2dguitextdisplay

GUI text not showing in scene or game view

I have set the transform positions to 0, put the text in a default layer, in the hierarchy it is not a child of the canvas. I added a script which shows a highscore, but it wont show in the game or scene view! Very annoying, I feel like I have tried everything. I see that in the text field in the inspector of the game object which has the gui text component attached, the text changes to what I want. However, it wont show in the game or scene view. i want the text to be in the center middle, with text alignment to be center as well. Heres the script im using: using UnityEngine; using System.Collections;

 public class ShowScore : MonoBehaviour {
 
     static int highScore = 0;
 
     void Start () {
         PlayerPrefs.GetInt("highScore",highScore);
         highScore = PlayerPrefs.GetInt ("highScore", highScore);
         guiText.text = "HS:" + highScore;
         }
                     
                     
         
 
     
 
 }
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taxvi · Jan 15, 2015 at 12:12 PM 2
Share

hey buddy, I see you are new to GUI. for the sake of all that is holly, don't learn it. learn unity UI, or nGUI, or anything else, but not GUI.

avatar image rob5300 · Jan 15, 2015 at 09:38 PM 0
Share

For any Unity 4.6 UI object to work it HAS to be under a Canvas. And the alignment should be very easy to do with positioning the text in the scene view. Try starting over by trying to insert a new ui text object and work from there. Also as the guy below stated, UnityEngine.UI needs to be declared in the file too to allow you to interact with them via scripts.

Official Unity UI Tutorials: http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-text

avatar image Eric5h5 · Jan 15, 2015 at 09:41 PM 2
Share

Yeah, GUIText and GUITexture are basically obsolete. Don't waste time on them.

avatar image Elit3d · Jan 15, 2015 at 10:11 PM 1
Share

@kastenessen you are wrong, there is so much more you can do with the new UI.

avatar image rob5300 · Jan 15, 2015 at 10:26 PM 1
Share

@$$anonymous$$astenessen The ui is NOT limited from scripting, the problem is the ui classes are not accessible from the default namespace imports. You have to also declare using UnityEngine.UI; like in the answer below. Just have a quick look at the official tutorials, live training and documentation to see what is possible!

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Elit3d · Jan 15, 2015 at 12:34 PM

If you are using 4.6 unity it is much easier to do it like this:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class ShowScore : MonoBehaviour {
     
     static int highScore = 0;
     public Text guiText;
     
     void Start () {
         PlayerPrefs.GetInt("highScore",highScore);
         highScore = PlayerPrefs.GetInt ("highScore", highScore);
     }
     
     void Update() {
         guiText.text = "HS: " + highScore;
     }
 }
 


I haven't tested it so if you get any errors let me know. Just wrote it on the spot so probably has errors, maybe not. Hope this helps

EDIT: It is very important you include using UnityEngine.UI; on top otherwise you will encounter errors!

Comment
Add comment · Show 20 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fatmanspineapple · Jan 15, 2015 at 01:34 PM 0
Share

What object do I attach this script to?

avatar image gjf · Jan 15, 2015 at 02:25 PM 0
Share

line #11 isn't needed...

avatar image Elit3d · Jan 15, 2015 at 02:37 PM 0
Share

@fatmanspineapple any object you like, as long as you assign the text object to it

avatar image Elit3d · Jan 15, 2015 at 02:38 PM 0
Share

The text object comes from GameObject > UI > Text

avatar image Kiwasi · Jan 15, 2015 at 11:10 PM 1
Share
 public Text guiText;

That's just asking for confusion :)

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

I have a problem with coins 1 Answer

2DHingeJoints not flipping with characters localScale C# unity ragdoll 1 Answer

Transforming position in y-axis (going in the middle) in Unity 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges