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;
    }

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!

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.