Is there a better way than using case and break for this. Everything works great how it is but in my mind i would like expand on my knowledge to better my coding skills. My end goal is to be able to select what gun i want from the inspector via a String and not an Int (My Animator uses SetInterger) so i would have to convert a String to an Int and that’s not something i know how to do proficiently as of yet.
Any help would as always be greatly appreciated.
public class AIAnimation : MonoBehaviour
{
private aiMovement aiM;
private Animator anim;
public int weaponType;
public GameObject[] activeWeapons;
void Start () {
aiM = this.transform.parent.GetComponent<aiMovement>();
anim = GetComponent<Animator>();
weaponSelector (weaponType);
}
void weaponSelector(int weaponType)
{
switch (weaponType)
{
case 1:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 2:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 3:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 4:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 5:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 6:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 7:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 8:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 9:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
case 10:
weaponDeactive();
activeWeapons[weaponType].SetActive(!activeWeapons[weaponType].activeSelf);
anim.SetInteger("WeaponType_int", weaponType);
break;
}
}
public void weaponDeactive(){
foreach (GameObject go in activeWeapons)
go.SetActive (false);
}
}