I’m very new to coding and I’m simply trying to enable one weapon while disabling the others by pressing a button on my weapon wheel. The weapon wheel works, I just can’t find any good info on this specific topic.
using UnityEngine.UI;
using UnityEngine;
public class WeaponWheelController : MonoBehaviour
{
public Animator anim;
private bool weaponWheelSelected = false;
public Image selectedItem;
public Sprite noImage;
public static int weaponID;
int totalWeapons = 1;
public int currentWeaponIndex;
public GameObject[] guns;
public GameObject weaponHolder;
public GameObject currentGun;
void Start()
{
totalWeapons = weaponHolder.transform.childCount;
guns = new GameObject[totalWeapons];
for (int i = 0; i < totalWeapons; i++)
{
guns *= weaponHolder.transform.GetChild(i).gameObject;*
guns*.SetActive(false);*
}
guns[0].SetActive(true);
currentGun = guns[0];
currentWeaponIndex = 0;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
weaponWheelSelected = !weaponWheelSelected;
}
if (weaponWheelSelected)
{
anim.SetBool(“OpenWeaponWheel”, true);
}
else
{
anim.SetBool(“OpenWeaponWheel”, false);
}
switch (weaponID)
{
case 0: //nothing is selected
selectedItem.sprite = noImage;
break;
case 1: //pistol
Debug.Log(“Pistol”);
break;
case 2: //rifle
Debug.Log(“Rifle”);
break;
case 3: //shotgun
Debug.Log(“Shotgun”);
break;
case 4: //plasma
Debug.Log(“LaserReflector”);
break;
}
}
}