This tooltip text script works perfectly fine, i want to add a background to it, can any 1 guide me what to do ? plz explain step by step and in simple language…
thanks a lot in advance for ur time
var toolTipText = “”; // set this in the Inspector
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 = toolTipText;
}
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+21,300,60), currentToolTipText, guiStyleBack);
GUI.Label (Rect (x-150,y+20,300,60), currentToolTipText, guiStyleFore);
}
}
Numid
June 27, 2011, 6:40am
2
If I understand this code snippet well, one label is drawn on the top of the other in order to provide a shadow effect or to gain contrast with what’s behind the tooltip message. Well.
I would suggest you this:
Add the following line at the top of your script. It enables you to select your background image from the editor (background image, was it what you have meant?).
var backgroundTexture : Texture2D;
In the Start
function, add the following line. The background image is now part of the style of the label that will be drawn (foreground label).
guiStyleFore.normal.background = backgroundTexture;
One more thing: make sure the dimension of your background image is 300px width and 60px height, which is the dimension of your tooltip label(s).
i did as u said , but got this error
NullReferenceException: Object reference not set to an instance of an object
mouseOver.Start () (at Assets/mouseOver.js:14)
and
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUI.Label (Rect position, UnityEngine.GUIContent content, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/GUI.cs:91)
UnityEngine.GUI.Label (Rect position, System.String text, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/GUI.cs:85)
mouseOver.OnGUI () (at Assets/mouseOver.js:62)
Numid
June 27, 2011, 7:56pm
4
Have you set the background image from the editor/inspector ?
I need the full script to tell you exactly what’s wrong.
yes i added it
see here -
http://www.image-share.com/ijpg-741-131.html
full script below…simple add a cube and assign ur script to it
var toolTipText = “”; // set this in the Inspector
var backgroundTexture : Texture2D;
private var currentToolTipText = “use W,A,S,D keys to move and mouse to rotate view”;
private var guiStyleFore : GUIStyle;
private var guiStyleBack : GUIStyle;
var clickLeft : int = 0;
var mouseIsOnIT : int = 0;
function Start()
{
guiStyleFore.normal.background = backgroundTexture;
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 ()
{
mouseIsOnIT = 1;
currentToolTipText = toolTipText;
}
function Update ()
{
if (mouseIsOnIT == 1 Input.GetMouseButton(0))
{
clickLeft = 1;
Debug.Log(clickLeft + “Pressed left click.”);
// @ Numid u can ignore the below 2 lines
popupminmax.winClose = false;
popupminmax.minM =! true;
}
}
function OnMouseExit ()
{
mouseIsOnIT = 0;
currentToolTipText = “”;
}
function OnGUI()
{
if (currentToolTipText != “”)
{
var x = Event.current.mousePosition.x;
var y = Event.current.mousePosition.y;
GUI.Label (Rect (x-149,y+21,300,60), currentToolTipText, guiStyleBack);
GUI.Label (Rect (x-150,y+20,300,60), currentToolTipText, guiStyleFore);
}
}
Numid
June 27, 2011, 8:35pm
6
In the Start
function you attempt to update the guiStyleFore
object before initializing it. Replace the first and the second line of the function with (mere inversion):
guiStyleFore = new GUIStyle();
guiStyleFore.normal.background = backgroundTexture;
Does it solve your problem?