Ive got problem:
I want to hightlight button if it has been pressed, there are meant to be many buttons and one button represents a tool, so if a button is pressed then tool is selected... I just want to
highlight one button, that has been selected.
If one button is selected (highlighted) then other buttons cant be selected(highlighted)
Ive added a code, that doesnt work, but will say what i meant with all this....
Use a GUI.Toggle but style it like a button. This will utilize the skin to differentiate the selected button(s) from the unselected ones and the toggle supports the behavior for what you want. You will want to keep the state of each button in an array or dictionary(with something that identifies the tool) so you know which buttons are selected.
I just use this script on all my buttons.Just create a guiTexture and add this script. It allows me to change size when I mouse over, change color/texture when it's selected and it allow me to expose all those variables so I can freely toggle them in my editor. If you don't want to toggle color but texture replace guiTexture.color with guiTexture.texture.
var normalColor : Color;
var overColor : Color;
var selectedColor : Color;
var selectedOverColor : Color;
var size : int
var overSize : int
private var selected : boolean = false;
function Start () {
guiTexture.color = normalColor;
guiTexture.pixelInset.width = size;
guiTexture.pixelInset.height = size;
selected = false;
}
function OnMouseEnter () {
if(selected){
guiTexture.color = selectedOverColor;
}
else if(!selected){
guiTexture.color = overColor;
}
guiTexture.pixelInset.width = overSize;
guiTexture.pixelInset.height = overSize;
}
function OnMouseExit () {
if (!selected) {
guiTexture.color = normalColor;
}
else if (selected) {
guiTexture.color = selectedColor;
}
guiTexture.pixelInset.width = size;
guiTexture.pixelInset.height = size;
}
function OnMouseDown () {
if (!selected) {
selected = true;
guiTexture.color = selectedColor;
}
else if (selected) {
selected = false;
guiTexture.color = normalColor;
}
}