- Home /
Question by
raycosantana · Jan 17, 2013 at 02:25 AM ·
booleanswitchactive
switching the active boolean
hello
I have several booleans and I want only one at a time to be active, what its the propper way to do this in C#?
Im doing
if (Input.GetButtonDown("number1")){
number1 = true;
number2 = false;
number3 = false;
number4 = false;
number5 = false;
print ("pulsado el numero1");
}
if (Input.GetButtonDown("number2")){
number1 = false;
number2 = true;
number3 = false;
number4 = false;
number5 = false;
print ("pulsado el numero2");
}
....
and Im pretty sure its not the propper way to do it, (doesnt even work anyways) this is for everytime the player presses one of the numbers changes the animation to match the corresponding weapon.
Comment
Best Answer
Answer by Lovrenc · Jan 17, 2013 at 02:27 AM
Get rid of these booleans and create single variable.
Then use Enumeration for controlling your state.
e.g.:
enum Weapon {gun, shotgun, machineGun};
Weapon currentWeapon = Weapon.gun;
we meet again Lovrenc! Im gona try that right now! thanks