- Home /
Question by
lod_ashtaroth · Jul 06, 2019 at 05:56 AM ·
unityeditorbooleanboolswitching
How would I make 1 bool true whilst making others false
I have 3 bools that basically determine a players damage multiplier. I want to make it so that if you check 1 of any of these 3 bools, the other 2 check false.
How would I go about this?
Heres my current code
public bool lvl1_Dmg;
public bool lvl2_Dmg;
public bool lvl3_Dmg;
void Update ()
{
DMGMulti();
}
void DMGMulti()
{
if(lvl1_Dmg)
{
lvl1_Dmg = true;
lvl2_Dmg = false;
lvl3_Dmg = false;
}
else if(lvl2_Dmg)
{
lvl1_Dmg = false;
lvl2_Dmg = true;
lvl3_Dmg = false;
}
else if (lvl3_Dmg)
{
lvl1_Dmg = false;
lvl2_Dmg = false;
lvl3_Dmg = true;
}
}
Comment
Answer by EternalClickbait · Jul 06, 2019 at 06:31 AM
First off, why not use a const array with the values in it?
int[] damageValues = {1,2,3}
Or just use a variable for the multiplier?
int damage = 5
If you really need it, here's the simpler code:
public bool lvl1_Dmg;
public bool lvl2_Dmg;
public bool lvl3_Dmg;
void Update ()
{
DMGMulti();
}
void DMGMulti()
{
if(lvl1_Dmg)
lvl2_Dmg = lvl3_Dmg = false;
else if(lvl2_Dmg)
lvl1_Dmg = lvl3_Dmg = false;
else if (lvl3_Dmg)
lvl1_Dmg = lvl2_Dmg = false;
}