Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by paco morales · Jan 20, 2013 at 11:32 PM · animationguiif

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;
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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!

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image paco morales · Jan 22, 2013 at 02:45 AM 0
Share

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)
  
 
  
  
 
          

   
 
avatar image paco morales · Jan 22, 2013 at 02:45 AM 0
Share

$$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");    
 }
  
avatar image justin35f · Jan 22, 2013 at 04:48 AM 0
Share

That looks fine man. What I usually use my case statements are when I am checking a variable that has several 'states'.

avatar image paco morales · Jan 22, 2013 at 06:49 AM 0
Share

Thanks $$anonymous$$an,n ow I'm going to continue with my project :)

avatar image justin35f · Feb 11, 2013 at 09:40 PM 0
Share

Thanks paco, glad I could help lead you in the right direction.

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5 GUI system 1 Answer

I want to do something if animation ends 1 Answer

Activating UI panel on GameObject Click/Destroy 0 Answers

create game and watch style frame by frame animation 0 Answers

How do i make a text box appear on screen after a chest has been opened? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges