- Home /
detect mouseover with grid buttons?
Hello, I know of the tool tip function for on gui, but im trying to detect which button is is under the mouse to bring up a full item description in a scroll box for an inventory. I am using the basic grid
var itemDescription: String; var selectionStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
function OnGUI () {
var selectionGridInt : int = -1;
selectionGridInt = GUI.SelectionGrid (Rect (25, 25, 100, 30), selectionGridInt, selectionStrings, 2);
for ( i = 0; i < items.length; i ++ ) {
if ( selectionGridInt == i ) {
//blah blah
}}}
// i dont even know//
function OnMouseOver(selectionGridInt){
for ( i = 0; i < items.length; i ++ ){
??? if(selectionGridInt == i) ???
itemDescription = items[i].GetComponent(itemScript).description;
Thanks for any help!
Not a real solution, but if it comes down to the wire you can use Rect.Contains for the individual buttons: http://unity3d.com/support/documentation/ScriptReference/Rect.Contains.html
Answer by BerggreenDK · Jul 20, 2011 at 11:21 PM
selectionGridInt is the variable containing the current selected "button" from the grid.
if you put all your "results/descriptions" in another array and let the index of this array match with your grid buttons, you should be able to get it.
lets say you have selected the [Grid 3] button
then selectionGridInt would return 2 as index value (0,1,2,3 for possible grid values).
Then in your array of descriptions:
// place these in the init section of your code.
string[] descriptions = new String[]{ "Description 1", "Description 2",
"Description 3", "Description 4" }
// notice the index variable, place the following lines after the GUI Grid thing.
selectionDescription = descriptions[ selectionGridInt ];
// show us the result in the console window
Debug.Log(selectionDescription);