- Home /
Static var triggerGo?
Hi everyone,
I'm using a GUI with several buttons, each button activated one animation in other script attached to an object.
Thanks for your help,
Can I use the same variable trigger Go, with different number? like this.
 // For Example.....
 
     if (buttonsGUI.triggerGo ==1){
     animacion01();
     buttonsGUI.triggerGo = 0;
     } 
     if (buttonsGUI.triggerGo ==2){
     animacion02();
     buttonsGUI.triggerGo = 0;
     }
     if (buttonsGUI.triggerGo ==3){
     animacion03();
     buttonsGUI.triggerGo = 0;
     }
     if (buttonsGUI.triggerGo ==4){
     animacion04();
     buttonsGUI.triggerGo = 0;
     }
Or use a different variable for each one animation? Like this?
     if (buttonsGUI.tryGo ==1){
     animacion01();
     buttonsGUI.erGo = 0;
     } 
     if (buttonsGUI.torGo ==2){
     animacion02();
     buttonsGUI.arGo = 0;
     }
     if (buttonsGUI.maGo ==3){
     animacion03();
     buttonsGUI.rarGo = 0;
     }
     if (buttonsGUI.solGo ==4){
     animacion04();
     buttonsGUI.moonGo = 0;
     }
Answer by justin35f · Jan 21, 2013 at 12:08 AM
Hey Paco! I think what you are looking for is a case statement:
 switch(buttonsGUI.triggerGo)
 {
     case 0:
         // Do stuff here
     break;
     case 1:
         animacion01();
         buttonsGUI.triggerGo = 0;
     break;
     case 2:
         animacion02();
         buttonsGUI.triggerGo = 0;
     break;
     case 3:
         animacion03();
         buttonsGUI.triggerGo = 0;
     break;
     case 4:
         animacion04();
         buttonsGUI.triggerGo = 0;
     break;
     default:
         // Usually for unhandled scenarios
     break;
 }
Let me know if this helps, or if it's not quite right!
Hi Justin and LP-Ga$$anonymous$$g, thanks for your help.
Now my scripts are working well, I tried to use both solutions, but I have problems with the number 0 and 1 because I use them for one button that makes double function.
So, I'm using the same scrips. Please see to my scripts if I'm making something wrong. Now are working well.
http://www.youtube.com/watch?v=IwIJDYAv55$$anonymous$$
GUI Scrip
  static var triggerGo : int;
 static var cameraGo : int;
 static var swithGo : int;
 static var disassembleGo : int; 
 static var vSliderValue : float = 0.0;
 
 var onGo = true; 
 var sonGo = true;
 
 var vthumbStyle : GUIStyle;
 var vsliderStyle : GUIStyle;
 var Skin_power : GUISkin; 
 var Skin_lock : GUISkin;
 var Skin_tool : GUISkin;
 var Skin_key : GUISkin;
 var Skin_battery : GUISkin;
 var Skin_Disassemble : GUISkin;
 var beep : AudioClip;
 
 function OnGUI (){
 
      vSliderValue = GUI.VerticalSlider (Rect (887.5, 10, 50, 203), vSliderValue, 1.0f, 0.0f,vsliderStyle,vthumbStyle);
    
        GUI.skin = Skin_power;
     if (GUI.Button(Rect(870,227,80,56),"")){
      audio.PlayOneShot(beep);
     triggerGo = (triggerGo + 1) % 2;
     buttonSlide();     
       }     
  
     GUI.skin = Skin_lock;
     if (GUI.Button(Rect(870,286,80,56),"")){
      audio.PlayOneShot(beep);
     triggerGo = 2;
       }
  
      GUI.skin = Skin_tool;
     if (GUI.Button(Rect(870,345,80,80),"")){
     audio.PlayOneShot(beep);
        triggerGo = 3;
       cameraGo = 1;    
      }    
     
      GUI.skin = Skin_key;
     if (GUI.Button(Rect(870,428,80,39),"")){
     audio.PlayOneShot(beep);
     triggerGo = 4;
       }
      
     GUI.skin = Skin_battery;
     if (GUI.Button(Rect(870,470,80,39),"")){
     audio.PlayOneShot(beep);
     triggerGo = 5;
       cameraGo = 2;    
     }
 
     GUI.skin = Skin_Disassemble;
     if (GUI.Button(Rect(870,512,80,80),"")){
     audio.PlayOneShot(beep);
     disassemble();
     }        
 }
 
 // Doubles animations/////////////////////////////////////////////////////
 
 function buttonSlide() {
 
     if(onGo) {
        swithGo =1;
        onGo = !onGo;
     }
     else {
   
        swithGo =2;
        onGo = !onGo;
     }
 }    
 
 function disassemble() {
 
     if(sonGo) {
       disassembleGo =1;
       sonGo = !sonGo;
     }
     else {
   
        disassembleGo =2;
       sonGo = !sonGo;
     }
 }
 
 @script RequireComponent(AudioSource)
  
 
  
  
 
          
   
 
$$anonymous$$y Script Animations
 static var appear$$anonymous$$eyGo : int; 
 function Update (){
 
 // Doubles animation....
 
     if (buttonsGUI.swithGo ==1){
     animationA1();
     buttonsGUI.swithGo = 0;
     } 
     
     if (buttonsGUI.swithGo ==2){
     animationA2();
     buttonsGUI.swithGo = 0;
     } 
 
     if (buttonsGUI.disassembleGo ==1){
     animationB1();
     buttonsGUI.disassembleGo = 0;
     }     
         
     if (buttonsGUI.disassembleGo ==2){
     animationB2();
     buttonsGUI.disassembleGo = 0;
     } 
 
 // Singles animation....
  
     if(buttonsGUI.triggerGo ==2){
          animationC();
          buttonsGUI.triggerGo = 0;
      }
      
     if(buttonsGUI.triggerGo ==3){
          animationD();
          buttonsGUI.triggerGo = 0;
      }
      
     if(buttonsGUI.triggerGo ==4){
          animationE();
          buttonsGUI.triggerGo = 0;
      }     
 
     if(buttonsGUI.triggerGo ==5){
          animationF();
          buttonsGUI.triggerGo = 0;
      }               
 }
  
 // Doubles animation///////////////////////////////////////////
 
 function animationA1(){
     animation.PlayQueued("PowerOn");
 }
 
 function animationA2(){
     animation.PlayQueued("PowerOff");
 }
 
 function animationB1(){
     animation.PlayQueued("DisassembleOn");
  
 }
 
 function animationB2(){
     animation.PlayQueued("DisassembleOff");
  
 }
 
 // Singles animation....
  
 function animationC(){
     animation.PlayQueued("ShaftLockButtonDown");
     animation.PlayQueued("ShaftLockButtonUp");
 }
   
 function animationD(){
      yield WaitForSeconds (3.5);
      appear$$anonymous$$eyGo = 2;
      animation.PlayQueued("ShaftLockButtonDown");
     // 1:25 Duration Tool
     animation.PlayQueued("ToolGo");
     animation.PlayQueued("DiscGo");
     animation.PlayQueued("DiscBack");
     animation.PlayQueued("ToolBack");
      // 1:03 Duration ShaftLockButtonUp    
     animation.PlayQueued("ShaftLockButtonUp");
  
 }
   
 function animationE(){
     animation.PlayQueued("$$anonymous$$ey");
     appear$$anonymous$$eyGo = 1;
 }
 
 function animationF(){
     yield WaitForSeconds(5.35);
     animation.PlayQueued("BatteryGo");
     yield WaitForSeconds(4.0);
     animation.PlayQueued("BatteryBack");    
 }
  
That looks fine man. What I usually use my case statements are when I am checking a variable that has several 'states'.
Thanks $$anonymous$$an,n ow I'm going to continue with my project :)
Thanks paco, glad I could help lead you in the right direction.
Answer by LPGaming-Company · Jan 20, 2013 at 11:39 PM
You would have to set up an array for this to work, I don't know if the original triggerGo variable is an array or not, but it should be a simple edit in the unity code.
I'm guessing buttonsGUI is your own file though, because I've never seen it before, so go ahead and do it like this
 public int[] triggerGo;
You can use the inspector to drag all the stuff in, remember it starts at 0
so
 if(triggerGo = 0)
 if(triggerGo = 1)
 if(triggerGo = 2)
 if(triggerGo = 3)
EDIT:
I would have to see buttonsGUI to help any farther.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                