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 pnoct · Jan 10, 2012 at 05:46 AM · textchangehudpropertygui-text

Simple question about Guitext

I've set up a GUItext instance to display on the screen, and was trying to drag and drop it on to a prefab that requires access to it to alter the text property. It won't let me do this, and clicking on the rollout button next to the public variable "score"(which I declared as a public GUIText variable in my script) in the explorer shows my assets folder in the "select guitext" window as being empty. Just wondering if I'm going about this the right way, is it possible to use a guitext variable in this way, or is there a better way to do it?

Comment
Add comment · Show 1
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 dwumpus · Nov 29, 2014 at 05:23 PM 0
Share

I'm new to Unity and was going thru the beginner tutorials and had this same issue when it came to adding the "Count" of cubes. When I tried to drag the GUIText object I had created from the Hierarchy tab into the inspector and onto the controller script component field box it did not work. I'm going to try going to my script and changing the public variable to accept a GameObject ins$$anonymous$$d and then cast it as a GUIText internal to my script to use it. I would like to know if it is a problem with the designer or the programmer (me) though, because I'm learning.

BTW, I'm a pretty accomplished c# developer professionally, so don't spend extra time dumbing down the answer unless you feel the community would benefit.

1 Reply

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

Answer by dannyskim · Jan 10, 2012 at 05:12 PM

Hmm. I'm able to set a GUIText as a public variable in the inspector no problem, whether it just be plainly in the scene or setting it myself through code.

You may want to consider trying making the Score part of a prefab first, and then seeing if you can select it. Access to some objects requires that they be a prefab before they're assigned as variables in the inspector.

Comment
Add comment · Show 3 · 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 pnoct · Jan 10, 2012 at 07:09 PM 0
Share

Thanks for the suggestion, I tried making it a prefab, but no dice. I could drag the prefab on to the public variable, but not the instance of the GUItext I wanted to refer to.

avatar image dannyskim · Jan 10, 2012 at 07:27 PM 2
Share

I'm not quite sure why this is happening, I'll see if I can replicate the issue throughout my work today. $$anonymous$$y only other suggestion as a workaround would be to create a public static text variable on the object you were originally wanting to attach the GUIText to, and then create another script on the actual GUIText item to access and set the static variable accordingly to the GUIText.

Or you can try doing a GameObject.Find() during runtime and storing it as a private static variable. I know doing a GameObject.Find() will absolutely allow you to store the variable in your script.

So for example:

guiTextInstance = GameObject.Find( "GuiTextNameHere" ).GetComponent(GUIText)();

That's for c#, and I believe the syntax is correct. I haven't tried it myself. The parentheses surrounding the GUIText word actually need to be less than / greater than signs.

avatar image pnoct · Jan 13, 2012 at 07:36 AM 0
Share

That did the trick :-) thanks.

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

6 People are following this question.

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

Related Questions

Display controls in-line with text? 0 Answers

Written objectives in unity 3D 0 Answers

Change text value 3 Answers

Updating GUI text 0 Answers

Display a block of text to the screen 0 Answers


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