- Home /
tooltip to show from array C#
hello there fellow coders! im completely new to the whole unity and coding in general but i want to learn :) im atm building a little inventory, and i got it to put teh items into an array that i display via GUI buttons, my question is how do i make it so when i hover over the item in my inventory, that it read the "tooltip" string i got under my item.
this is my inventory script so far. thanks alot in advance!
using UnityEngine;
using System.Collections;
public class inventory : MonoBehaviour {
public GameObject[] itemSlots = new GameObject[10];
public int i = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUILayout.BeginArea(new Rect(Screen.width-144, Screen.height-180, 200, 200));
Rect r = new Rect(0,0,35,35);
for (i = 0; i < itemSlots.Length; i++){
if (GUI.Button(r,itemSlots[i].GetComponentInChildren<item>().icon)){
}
r.x += 36;
if(r.x > 108) {
r.x = 0;
r.y += 36;
}
}
GUILayout.EndArea();
}
}
my item script if someone needs it is here:
using UnityEngine;
using System.Collections;
using UnityEngine;
using System.Collections;
public class item : MonoBehaviour {
public bool isEquipped = false;
public int itemId;
public int buyPrice;
public int sellPrice;
public GameObject itemVisual;
public Texture2D icon;
public string tooltipText;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void isEquippedCheck (){
if (isEquipped == true){
itemVisual.renderer.enabled = true;
}
else itemVisual.renderer.enabled = false;
}
}
First of you need to have a way to figure out if the mouse is hovering over a button. To do so you could use this.
Answer by Muuskii · Jul 10, 2012 at 03:41 PM
Sorry I'm not going to read through your wall of code to find if you tried this already, but take a look at this:
http://docs.unity3d.com/Documentation/ScriptReference/GUI-tooltip.html
Your answer
Follow this Question
Related Questions
multiple rows, in an array in C# 2 Answers
Dynamic Resizing of tooltip to match content? 1 Answer
Inventory Help 0 Answers
How to select a texture in an inventory? 0 Answers
GUI Button to create another GUI 1 Answer