- Home /
Question by
smhtx · May 11, 2015 at 07:35 AM ·
unity 5javascriptonmouse
GuiText on Object when Camera in Center
hello. so far i have found a script using the OnMouseOver function to have guiText appear on objects and it works. however since i am in FPV i want to make it when the center of the camera is on a object it shows the guiText. this is my first post. love the program.
this is the code in java thanks
var text = "YOUR TEXT HERE";
private var currentToolTipText = "";
private var guiStyleFore : GUIStyle;
private var guiStyleBack : GUIStyle;
function Start()
{
guiStyleFore = new GUIStyle();
guiStyleFore.normal.textColor = Color.white;
guiStyleFore.alignment = TextAnchor.UpperCenter ;
guiStyleFore.wordWrap = true;
guiStyleBack = new GUIStyle();
guiStyleBack.normal.textColor = Color.black;
guiStyleBack.alignment = TextAnchor.UpperCenter ;
guiStyleBack.wordWrap = true;
}
function OnMouseEnter ()
{
currentToolTipText = text;
}
function OnMouseExit ()
{
currentToolTipText = "";
}
function OnGUI()
{
if (currentToolTipText != "")
{
var x = Event.current.mousePosition.x;
var y = Event.current.mousePosition.y;
GUI.Label (Rect (x-149,y+40,300,60), currentToolTipText, guiStyleBack);
GUI.Label (Rect (x-150,y+40,300,60), currentToolTipText, guiStyleFore);
}
}
Comment