- Home /
Switching between set of components
I have set of scripts, every script is finished tool (i.e. it have user interface and all nessesarry things to work).
i want to switch between them. I know 1 oblivious "shotgun" way:
(switch statement or anything else) case(1): script1.enabled = true; script2.enabled = false; script3.enabled = false; case(2): script1.enabled = false; script2.enabled = true; and so on, and on, and on... (i have around 10 elements :D)
Give me please some kind of "good" solution for this problem, i am missing something really simple.
Answer by ninjarob · Oct 30, 2011 at 07:58 PM
If every script is on the same object you can use SendMessage.
So add this onto every script
var ThisScriptID:int=0;
function ToggleScriptState(ScriptID:int){
if(ScriptID==ThisScriptID){
enabled = true;
}else{
enabled = false;
}
}
use the following call on the object they are on
gameObject.SendMessage("ToggleScriptState",ScriptInt);
It may also be worth looking into useing enums instead of Ints to make the code more readable
Your answer
Follow this Question
Related Questions
Toggle Switch 6 Answers
Neutral state for toggle buttons? 2 Answers
GUI window popup button 1 Answer
Little help with GUI Toggle needed 1 Answer
GUI Button selected changes color and stays until another button is clicked 1 Answer