• 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 Conect11 · Sep 24, 2013 at 07:01 PM · guitext

Feast or Famine with GuiText

I can't believe I'm asking t$$anonymous$$s. Go ahead, yell at me, tell me to search. I deserve it, because t$$anonymous$$s is a hella simple question that for some reason I haven't quite found the answer to.

You see an item. You pick it up. When you pick it up, I'd just like a brief little text to appear that says what you picked up, then disappear shortly after. "Congrats, you just found dirty underwear!" or somet$$anonymous$$ng like that.

So at first I couldn't get anyt$$anonymous$$ng to appear at all. After a little bit of tweaking, I got the text to appear, but it's there right from the start. So now the screen is littered with text boxes. Sorry, really. Here's the code. Thanks for helping, and God bless.

 var pickuphardtacktext = true;
 var textArea = new Rect(0,0,Screen.width, Screen.height);
 var pickuphardtack : GUIText;
 
 function Update () {
 
 }
 
 function OnTriggerEnter (col : Collider) {
 pickuphardtacktext = true;
 if (col.gameObject.tag == "Player") {
 
 Inventory.inventoryArray[1]++;
 
 
 Destroy(t$$anonymous$$s.gameObject);
 
 }
 
 }
 
 function OnGUI()
 {
 if(pickuphardtacktext)
 
 {
 GUI.Label(textArea, "You found a Hard Tack Cracker!");
 }
 
 
 }

Also, yep, I see that I have both a GuiText object appear, as well as text right in the script. Not wanting both, I just throwing stuff at the problem to see what would stick.

Comment
Add comment · Show 2
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 Jamora · Sep 24, 2013 at 07:47 PM 0
Share
avatar image Conect11 · Sep 24, 2013 at 07:56 PM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MauMaGau · Sep 24, 2013 at 09:36 PM

I've tackled somet$$anonymous$$ng similar by having a GUI script (attached to an empty game object with a load of other 'manager' scripts) with the following code in it's OnGui method:

 if(!String.IsNullOrEmpty(GUIMessageCenter)){
     GUI.Box(Rect(Screen.width / 2 - 200, Screen.height / 2, 400, 25), GUIMessageCenter);
 }

GUIMessageCenter being a public variable that I set from other scripts via a coroutine (to allow the message to remain for x seconds):

 GUIScript.GUIIMessageCenter = "Matter hose not connected";
 yield WaitForSeconds(2);
 GUIMessageCenter = "";

T$$anonymous$$s is pretty hacky, and could be much better written, but hopefully it gives you some ideas

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

How to get print to transfer to a GUI Text? 1 Answer

How do I get my GUI text to open on awake? 1 Answer

GUI Text Score counter 3 Answers

Gui Text Script 4 Answers

Intro GUI Text Script... 3 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