Hey, i am making a FPS and am currently working on a weapon switching and pickup system. I have a list of gameobjects (my weapons) but i am not sure how to set only the current weapon to active, does anybody know the solution? My current switching system also seems too complex and i am wondering if there is a better way to do this? Thanks in advance
Here is part of my code:
public List weapons;
public int maxWeapons = 2;
public GameObject currentWeapon;
public int arrayPos = 0;
private void Start()
{
}
private void Update()
{
//currentWeapon.SetActive(true);
if ((Input.GetAxis("Mouse ScrollWheel") > 0f))
{
Debug.Log(weapons[arrayPos]); //Prints current value to console.
if (arrayPos >= weapons.Count - 1)
{
arrayPos = 0;
}
else
{
arrayPos += 1;
}
}
if ((Input.GetAxis("Mouse ScrollWheel") < 0f))
{
Debug.Log(weapons[arrayPos]); //Prints current value to console.
if (arrayPos <= 0)
{
arrayPos = 1;
}
else
{
arrayPos -= 1;
}
}