- Home /
Question by
blackshtormx · Sep 13, 2014 at 02:10 PM ·
guitexthideindexshow
show-hide some GUItexts in one script
I have script and it is working with 1 Guitext but when I am changing code to use some guitexts,(using []) nothing works any ideas? here is the script:
var levelObject : GUIText[];
var levelobjectisenabled : boolean;
function Start () {
levelobjectisenabled = levelObject.enabled = false;
}
function OnMouseDown () {
if (levelobjectisenabled) {
levelobjectisenabled = levelObject.enabled = false;
} else {
levelobjectisenabled = levelObject.enabled = true;
}
}
Comment
Are you attaching GUI Texts to your array in the inspector? Also if you have an array, you should access it like this: levelObject[i].enabled = false;
Answer by zharik86 · Sep 13, 2014 at 07:04 PM
For your array create loop:
var levelObject : GUIText[];
var levelobjectisenabled : boolean;
function Start () {
levelobjectisenabled = false;
this.myChange(levelobjectisenabled); //call function
}
//create new function
function myChange(tpCh: boolean) {
for(var i: int = 0; i < levelObject.Length; i++) {
levelObject[i].enabled = tpCh;
}
}
function OnMouseDown () {
if (levelobjectisenabled) {
levelobjectisenabled = false;
this.myChange(levelobjectisenabled); //call function
} else {
levelobjectisenabled = true;
this.myChange(levelobjectisenabled); //call function
}
}
I hope that it will help you.
Your answer
Follow this Question
Related Questions
Hide/Show part of a GameObject 3 Answers
Setting guiTexture to false works, but to true doesn't. 2 Answers
Object Visibility 2 Answers
Show GUI on collision 2 Answers
Layers Show/Hide not hiding children with showing parent 0 Answers