|
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 Here are the questions:
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): Full code here:
(comments are locked)
|
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. 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?
Feb 17 '11 at 12:42 PM
kakubei
(comments are locked)
|

I was able to solve the fade in issue with this function:
function FadeIn(myVal :float, myDuration : float){ var result : float; result = Mathf.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.
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.