I’ve been using this code from the forum, can’t remember the source, and I’ve edited it from gui.buttons so I can use gameobjects instead, which are just guiText for my game menu. They are a specific font and size and It works so you can scroll through them on the keys and select with space bar, but you can not see which one is selected, was hoping of some way of highlighting or changing the colour of the current selected gameobject. Thank you for any help, I also hope I’ve given enough information and posted correctly ![]()
var menuItems : GameObject[];
var selectedIndex = 0;
function menuSelection (menuItems, selectedItem, direction) {
if (direction == "up") {
if (selectedItem == 0) {
selectedItem = menuItems.length - 1;
} else {
selectedItem -= 1;
}
}
if (direction == "down") {
if (selectedItem == menuItems.length - 1) {
selectedItem = 0;
} else {
selectedItem += 1;
}
}
return selectedItem;
}
function Update ()
{
if (Input.GetKeyDown("down")) {
selectedIndex = menuSelection(menuItems, selectedIndex, "down");
}
if (Input.GetKeyDown("up")) {
selectedIndex = menuSelection(menuItems, selectedIndex, "up");
}
if (Input.GetKeyDown("space")) {
handleSelection();
}
}
function handleSelection()
{
switch (selectedIndex)
{
case 0:
Application.LoadLevel("Frontier");
break;
case 1:
// Application.LoadLevel("Options");
break;
case 2:
// Application.LoadLevel("About");
break;
case 3:
Application.Quit();
break;
default:
Debug.Log ("None of the above selected..");
break;
}
}