- Home /
Text pop up when mouse over gui button
Hi, I'm working on an inventory for my game and to make stuff take less space on the screen I decided to use pictures instead of text were the items are, now I only whant some text to show up at the mouse when hovering over the item in the inventory (Also show how much of it you got).
Here is some code that I´m using:
The Inventory script:
var targetScript: Player;
var Inventory = false;
var YellowFlowerButton : Texture;
function OnGUI(){
if(Inventory){
GUI.Box (Rect (0,0,Screen.height,Screen.width), "Inventory");
if (GUI.Button (Rect (10,Screen.width/2,Screen.height/2.5,Screen.width/20), YellowFlowerButton)) {
if(targetScript.shop == true){
if(targetScript.YellowFlower >= 1){
targetScript.YellowFlower -= 1;
targetScript.YellowFlowers = "Yellow Flowers: " + targetScript.YellowFlower;
targetScript.Coin += 2;
}
}
}
}
The player script:
var YellowFlower : int;
//ITEM PICKUP
//YELLOW FLOWERS
@HideInInspector
var YellowFlowers = "Yellow Flowers: 0";
@HideInInspector
var YellowFlowerPick : GameObject = null;
@HideInInspector
var YellowFlowerPick2 = false;
function OnTriggerEnter(other : Collider){
//ITEM PICKUP
//YELLOW FLOWERS
if(other.tag == "YellowFlower"){
YellowFlowerPick = other.gameObject;
YellowFlowerPick2 = true;
}
}
function OnTriggerExit(other : Collider){
//ITEM PICKUP
//YELLOW FLOWER QUEST
if(other.tag == "YellowFlower"){
YellowFlowerPick = null;
YellowFlowerPick2 = false;
}
}
function Update(){
//ITEM PICKUP
//YELLOW FLOWERS
if(YellowFlowerPick != null){
if(Input.GetButtonDown("Interact")){
YellowFlower += 1;
Destroy(YellowFlowerPick);
YellowFlowerPick2 = false;
YellowFlowers = "Yellow Flowers: " + YellowFlower;
}
}
}
function OnGUI(){
//ITEM PICKUP
//YELLOW FLOWERS
if(YellowFlowerPick2 == true){
GUI.Box (Rect (Screen.height+(Screen.height/17),Screen.width/2-(Screen.width/9),Screen.height/3,Screen.width/30), "\nPress E to take Yellow Flower");
}
}
This is only the code that has with the inventory and item pick up to do!
So if someone that is better at coding then I am I could really do with some help! (And I'm really sure there is lots of people out there that is.. xD)
Tnx! :)
//Elis
Answer by KillerStarBunny · Jun 17, 2014 at 03:18 AM
You want a tool tip http://docs.unity3d.com/ScriptReference/GUI-tooltip.html sorry it's just a link, I despise unity's GUI.
Answer by SteelArrow21 · Jun 17, 2014 at 03:23 AM
The only thing I could say is that rather than using:
void OnTriggerEnter ()
you could use:
void OnMouseOver()
Which you can learn more about here: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html
Also, I'm not sure if you're interested, but there is a third party tool that can be added to Unity which makes GUI so much easier. If oyu are interested, you can see it here: http://www.tasharen.com/?page_id=140
And you can see videos on it here: http://cgcookie.com/unity/cgc-courses/getting-started-with-ngui-for-unity/
You could do:
function On$$anonymous$$ouseEnter () {
//display text
}
function On$$anonymous$$ouseOver () {
//have text follow cursor
text.transform.localPosition = Input.mousePosition;
//or something along those lines
}
function On$$anonymous$$ouseExit() {
//Remove text
}
Your answer
Follow this Question
Related Questions
Gui Button Solid 2 Answers
GUI & GUI Text Disappear When Publishing 6 Answers
Change Text of GUI Button from Script 2 Answers
proper inventory system issue.. 1 Answer
how to change a gui button texture 1 Answer