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:
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.
answered Feb 17 '11 at 12:35 PM