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 CallToAdventure · Oct 14, 2010 at 11:13 AM · guitextureguitextmessagegui.labelin-game

In game message displayed on GUI - text and texture

Hello everyone,

Ive been finding answers to most of my questions here and I am therefore grateful. My game comes along very well so far. However I found myself stranded on one simple thing I cannot find answer for. I am an artist not a programmer and maybe that's the explanation right there.

Basically what I want to do is implement a simple way to display a message - text is ok, but I'd like to be able to use textures as well.

Example:

My player does this action. I want to be able to display a text and an image: "Well done" and the GUI.texture (the guy telling the player that, say, an instructor).

This is either triggered when the player has collision with some object, or the score is higher than 100.

Probably this has everything to do with triggering GUI elements but I simply cannot find a proper example anywhere.

Thanks in advance,

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
1

Answer by Rasmus Schlnsen · Oct 14, 2010 at 12:00 PM

I have created the following sample code real quick for you. Hope this is to any use. This basically triggers a GUITexture and GUIText to be displayed whenever an object collides with the object this script is attached to. It then starts a timer of guiTime seconds and then deactivates the GUI objects. Good luck!

using UnityEngine; using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

 public GUIText myGUItext;
 public GUITexture texture;
 public int guiTime = 2;


 void Start()
 {
     myGUItext.gameObject.active = false;
     texture.gameObject.active = false;
 }

 void OnTriggerEnter(Collider c)
 {

     myGUItext.text = "Display msg here";
     myGUItext.gameObject.active = true;
     texture.gameObject.active = true;
     // Start coroutine for deactivating gui elements
     StartCoroutine(GuiDisplayTimer());
 }

 IEnumerator GuiDisplayTimer()
 {
     // Waits an amount of time
     yield return new WaitForSeconds(guiTime);
     // Deactivate GUI objects;
     myGUItext.gameObject.active = false;
     texture.gameObject.active = false;
 }

}

Comment
Add comment · Show 5 · 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 CallToAdventure · Oct 15, 2010 at 12:30 AM 0
Share

1 $$anonymous$$ute took me to put it at work. Dear friend, you have my profound gratitude!

avatar image CallToAdventure · Oct 15, 2010 at 01:00 AM 0
Share

I'm probably missing something, but for every message I have to duplicate this script, right?

avatar image Rasmus Schlnsen · Oct 15, 2010 at 12:04 PM 0
Share

I'm glad you like it. You could add a public text variable and let the myGUItext.text = yourPublicVariable and then change the text for each gameobject you attach this script to. This isn't the preffered way of doing things, but if your new to coding, this might help you get your work done.

avatar image CallToAdventure · Oct 15, 2010 at 08:05 PM 0
Share

It does the job well; The problem is I cannot put a nice cartoonish bold text longer than about 7-10 words; I am thinking of some kind of break in the message to be displayed line by line, seen this somewhere on the wiki.

avatar image by0log1c · Mar 12, 2011 at 10:38 PM 0
Share

\n forces a linevbreak. If that's what youre' asking?

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

No one has followed this question yet.

Related Questions

Drawing UI text on GUI.DrawTexture , How to do it ? 1 Answer

Texture's Alpha is not Transparent when I use it as a GUI.label 1 Answer

Drawing a GUI onto a 3D object 0 Answers

Full GuiTexture-based user interface memory leak 1 Answer

GUI Final Scene/ Item Pickup 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