- Home /
Question by
AnthMurphy · Mar 12, 2017 at 05:32 PM ·
uiguiarrayobjectvisibility
GUI On button click change visibility of array objects
I'm trying to create a script which when a GUI button is pressed, it changes the visibility of my currently selected array object to disabled, and then enables the next object in the array.
It works when using GetKeyDown(D) But ive never used UI to do things before so i'm not sure how to translate it, heres my code:
var VisObjects : Transform[];
private var SelectedInList: int = 0;
public function Update () {
if(GUI.GetButtonDown(Button))
{
SelectedInList++;
if(SelectedInList>VisObjects.length-1){// go back to the beginning of list if i try and go above the last item.
SelectedInList =0;
}
ChangeVis();
}
if(Input.GetKeyDown(KeyCode.A))
{
SelectedInList--;
if(SelectedInList<0){ // go back to end of list if i try and go below the first item.
SelectedInList =VisObjects.length-1;
}
ChangeVis();
}
}
//runs through the entire list and makes everything on it invisible, then makes the single object you have selected visible.
public function ChangeVis(){
for(var i:int; i<VisObjects.length;i++){
VisObjects[i].transform.GetComponent.<Renderer>().enabled =false;
}
VisObjects[SelectedInList].transform.GetComponent.<Renderer>().enabled =true;
}
Comment