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 ShinyTaco · Feb 02, 2014 at 10:42 PM · arrayguitext

Why GUIText Array is Not Displaying GUIText?

Hey everybody,

I have a GUIText array with random tips that I would like displayed using Random.Range.

The random tips works fine. However, the code I am using will only display a random tip if the other GUITexts are enabled in the Hierarchy.

Code:

 var tipsArray : GUIText[];
 var currentTip:GUIText;
 
 function Start () {
     currentTip.enabled=false;
     showRandomTip();
 }
 
 function showRandomTip() {
     currentTip.enabled=true;
     currentTip = tipsArray[Random.Range(0,tipsArray.length)];
     currentTip.transform.position=Vector3(.5,.5,0);
     currentTip.fontSize=Screen.width/20;
     currentTip.enabled=true;
     print("SHOW currentTip");
 }


This works fine, but it only works when all the GUITexts are enabled in the Hierarchy. If I disable them, so that you cannot see them when the scene is running, No GUITexts are displayed.

Which makes sense, because they are not enabled.

I thought that currentTip.enabled=true; would fix that, but it doesn't.

Nothing shows.

Any idea what I'm doing wrong and how to fix this?

Thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Feb 02, 2014 at 10:51 PM

Your problem is the order of operations. You need to swap lines 10 and lines 11. You need to assign the new tip before you enable it. You are enabling the previous tip.

Assuming all the tips are at the same position, you could just as easily have only a single GUIText and set the text. Your tips would be an array of strings rather than an array of GUIText objects.

Comment
Add comment · Show 1 · 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 ShinyTaco · Feb 03, 2014 at 12:07 AM 0
Share

Hmm..I tried that and it still didn't work.

However, I followed your advice and used an array of Strings ins$$anonymous$$d.

Thanks for your help.

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

18 People are following this question.

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

Related Questions

When object i in Array is enabled, all other objects in Array are disabled. 3 Answers

C# Array, GuiText, assign strings. 2 Answers

[SOLVED] Puzzled why one particular GUIText won't appear 0 Answers

Unity3D: How to save an array of gameobjects with arrays of position in xml and load them back in correctly? 0 Answers

Array of audio clip arrays? 2 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