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
1
Question by kakubei · Feb 17, 2011 at 11:59 AM · guiguitexturefade

Fade In GUI on proximity

Hello, I have a similar problem to this post, but not quite: http://answers.unity3d.com/questions/28878/show-gui-text-when-distance-6

I have a bunch of paintings and I want a window to appear with information about each painting as the user gets near it. I'd like this to fade in and out as they approach and leave the proximity of each painting.

I have the proximity issue solved with a OnTriggerEvent(other: Collider) and I use a collision sphere for each painting (maybe there's a better way? Tried RayCasting but it didn't work).

Here are the questions:

  1. I'm using GUI.Box(Rect(10, 50, 300, 200), "Details:"); to draw the background. Should I be using a GUITexture instead? If so, how to manage it?
  2. I need to have different text for each painting, how can I accomplish this? If I create GUIText objects, they're always there and I don't know how to hide them then call them up again.
  3. Is there a way to tell Unity to read the text from a file?
  4. Lastly, how can I make the whole thing (background and text) fade in and out when called?

I know these are a lot of questions in one, but mostly I'm looking for guidance on how to accomplish this properly, I've been looking at the documentation and examples and have not been able to figure things out successfully, very new to Unity.

Thanks in advance.

I've enhanced the code so that now I can get the GUITexture to hide and then display when I am near an object. However, the Fade function is not working properly. It will not display at all if I have this code (copied from the Wiki): Fade.use.Alpha(myGuiTexture, 0.0, 1.0, 2.0, EaseType.In); or any other use of Fade, even in the "else" statement below. Any ideas are welcome.

Full code here:

private var myWindow: boolean; private var windowOn : boolean; private var windowRect : Rect = Rect (150, 150, 120, 50);//window parameters

var cuadroText : GUIText; var myGuiTexture : GUITexture;

myGuiTexture.enabled = false;

function OnTriggerEnter (other : Collider) { myWindow = true; }

function OnTriggerExit (other : Collider) { myWindow = false; // hide window }

function OnGUI () {

 if (myWindow == true) {

 // fade in del gui background
 myGuiTexture.enabled = true; // first we activate the guiTexture
 Fade.use.Alpha(myGuiTexture, 0.0, 1.0, 2.0, EaseType.In);
 GUI.Box(Rect(10, 50, 300, 200), "Details:"); // draw a box to make sure things are working.


 }  else {
         // fade out
     //Fade.use.Alpha(myGuiTexture, 1.0, 0.0, 3.0);
     myGuiTexture.enabled = false; // disable it.
     windowOn = false;
     }

}

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 kakubei · Feb 17, 2011 at 03:31 PM 0
Share

I was able to solve the fade in issue with this function:

function FadeIn(myVal :float, myDuration : float){ var result : float; result = $$anonymous$$athf.SmoothStep(myVal, myDuration, Time.deltaTime); return result; }

called inside the OnGUI() function, but I can't get the fadout to work since that has to happen outside the trigger. Even putting in inside the OnTriggerExit() doesn't work.

avatar image kakubei · Feb 18, 2011 at 02:03 PM 0
Share

I've got it working for fade in, but from what I've read there is no way to fade in the entire GUI, including GUITexture and GUIText and everything associated with it right? I have to fade each element individually.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Feb 17, 2011 at 12:35 PM

  1. Using a GUI.Box is sufficient in most cases.
  2. You can create a script that is attached to the painting, with a public string variable you can set in the inspector.
  3. Yes, you can use TextAsset to get a text file.
  4. You have keep a boolean value which is set OnTriggerEnter and OnTriggerExit and display the GUI when it is set.

So, what I would have done would be to create a script that listen for OnTriggerEnter, OnTriggerExit and OnTriggerStay. In Enter/Exit I would toggle visibility of the GUI. For the proximity fade, I would either make it timer based so that if you have entered the trigger, it fades up regardless of how far away you are, or use OnTriggerStay to calculate the distance to the center of the object. From this distance, you can calculate the transparency easily with an AnimationCurve and call Evaluate on this to get the alpha value (with the distance as parameter). Make the AnimationCurve public, and you can set it in the designer, or you can use the class methods EaseInOut or Linear. For the text (or any images), I would make a public GUIContent, so you can set text, image and tooltip if you like.

Then, create a trigger and add the script to the trigger. Set the values as you please, and you should have a basic system working.

To make the fade, you can use GUI.color. Just remember to restore it at the last moment of your OnGUI callback so rest of GUI isn't affected. If you want to make the timed approach, I can recommend using Mathf.MoveTowards, toggling the alpha values you want to move toward over time.

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 kakubei · Feb 17, 2011 at 12:42 PM 0
Share

Thanks for the reply. I don't need it to fade based on distance, just fade in when it collides and fade out when it's no longer in range. How would I use the GUI.color to make it fade? Given what I have above, seems the simplest solution no?

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

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Fade multiple GuiTextures in ONE Javascript 1 Answer

I have yet more problems with gui and bullets Help please 1 Answer

Display GUI when kill count reaches 5 1 Answer

Screen Resolution and GUI cutoff issue. Android. 1 Answer


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