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 Kuwmii · May 29, 2013 at 10:06 AM · guitriggertextdisplayhud

Display a Text/GUI on screen when triggerd with Fadein/Fadeout

Hey im new to unity scripting and i need help please.

i got this script

     #pragma strict
      
     var message : String = "Change Me";
     var displayMessage : boolean = false;
     var displayTime : float = 3.0;
      
     function OnTriggerEnter ()
     {
     displayMessage = true;
     yield WaitForSeconds (displayTime );
     displayMessage = false;
     }
      
     function OnGUI ( )
     {
     if ( displayMessage )
     {
     GUI.Label(new Rect(Screen.width * 0.5f - 50f, Screen.height * 0.5f - 10f, 100f, 20f), message);
     }
     }

How can i add a Size for text in that? and fade in and fadeout feature. Thanks!

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 Kuwmii · May 29, 2013 at 02:19 PM -1
Share

HELP SO$$anonymous$$EBODY :(

avatar image Graham-Dunnett ♦♦ · May 29, 2013 at 02:21 PM 1
Share

Two things, one, don't post comments as answers. Secondly, the community will respond if they know how to help you. $$anonymous$$aybe edit your question, and explain what documentation you have read, and what you need help with. It's unlikely that anyone is going to write your code for you. What have you managed to do for yourself in the last 4 hours?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TonyLi · May 29, 2013 at 03:10 PM

Unity GUI is a little complicated if you're new to scripting, so take your time learning it. It will eventually all make sense. :-)

For size, you'll probably want to use a GUIStyle, and set the fontSize.

See: http://docs.unity3d.com/Documentation/ScriptReference/GUIStyle.html

For fading, you'll want to set the text color's alpha value. For example, with a regular label, this is GUIStyle.normal.textColor.

The example below draws the text at font size 20, with 50% transparency.

     var alpha : float = 0.5;
     
     var style : GUIStyle;
     style = GUI.skin.label;
     style.fontSize = 20; // Set size of text to 20.
     style.normal.textColor = new (1, 1, 1, alpha); // Set color to white w/alpha.
     GUI.Label(new Rect(Screen.width * 0.5f - 50f, Screen.height * 0.5f - 10f, 
         100f, 20f), message, style);

(Warning: untested code above, plus my apologies in case I accidentally snuck some C# code in there out of habit.)

I recommend using a coroutine to handle fading in and out. A coroutine is a function that runs semi-independently from the main loop.

See: http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html

When fading in, the coroutine can change the value of alpha from 0 (completely transparent) to 1 (completely solid). Then OnGUI() can draw the label using the current alpha value.

 function FadeIn(duration : float) {
     if (duration > 0) {
         var startTime = Time.time;
         var endTime = start + duration;
         while (Time.time < endTime) {
             var elapsed = Time.time - startTime;
             alpha = (elapsed / duration);
             yield;
         }
     }
     alpha = 1;
 }
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 TonyLi · Jun 01, 2013 at 01:04 AM 0
Share

If this answer helped, please accept it. It might help others, too.

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

15 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

Related Questions

Help me with Gui Text 2 Answers

[4.6 JS] How to show GUI text on a trigger enter and then take it away on exit? 1 Answer

Need Text to Display After 5 Seconds 1 Answer

Using a trigger to make a scrollview appear and then disappear? 1 Answer

Displaying a Text when near a item, then display a hud (Press 'E' to investiage) + Halo appear 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