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! Code (csharp): 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: Code (csharp): 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; } }
Welcome to Unity, and glad to hear you're using C#. If I were you I'd stay away from Unity's GUI and invest in a proper 3rd party GUI like NGUI from the Asset Store. It will make your life much easier.
i already got that Ngui, but imo it cant give me what i want :/ i might just be stupid... but i cant get anything out of that :/ the build in inventory in Ngui is so hard coded and "this is the only way to do it" as it can be :/ kind a sucks... i know unity's gui eats a motherload of drawcalls, but how can i do this with Ngui? how can i do exactly what i did here just with Ngui? because i am stumped!
i know ^^ but i still have to start somewhere... and i have no idea where to start with Ngui, its like an engine inside an engine, and i am just stumped :/ anyone knows what i can use to get me startet making it with Ngui?
Just look for OnGUI tutorials its simple, also goto assets section of foum and find my ultimate package, its coming soon. Has inventory in it, and GUI.