Arena Shooter Weapon W/ Pickups Scrolling by MouseWheel
Hello All,
I have been struggling for 2 days now on how to implement this properly.
I am trying to design a game where you "pick up" weapons and they move into a predetermined slot. Akin to how Quake or Unreal Tournament played.
While I can get it working perfectly fine with alpha keys, its the mouse scrolling that is throwing me through a loop.
I currently have these variables in my player controller:
//GUNS GUNS GUNS
public Gun activeGun;
public List<Gun> allGuns = new List<Gun>();
public List<bool> unlockedGuns = new List<bool>();
public List<Gun> gunsAvailable = new List<Gun>();
public int currentGun = 0;
private int previousGun;
I have an equip function:
public void SwitchGun(int gunNumber)
{
if (cannotChangeWeapon) return;
//if (currentGun == gunNumber) return;
if (gunNumber < 0)
{
gunNumber = allGuns.Count - 1;
}
if (gunNumber > allGuns.Count - 1)
{
gunNumber = 0;
}
for (int i = 0; i < unlockedGuns.Count; i++)
{
if(i == gunNumber && unlockedGuns[i])
{
activeGun.gameObject.SetActive(false);
activeGun = allGuns[gunNumber];
activeGun.gameObject.SetActive(true);
previousGun = currentGun;
currentGun = gunNumber;
UIController.instance.ammoText.text = "AMMO: " + activeGun.ammo;
}
}
}
And the pick up function:
public bool WeaponPickup(string gunToAdd)
{
switch(gunToAdd)
{
case "Repeater":
if(unlockedGuns[1] == true)
return false;
else
{
unlockedGuns[1] = true;
gunsAvailable.Add(allGuns[1]);
return true;
}
case "Sniper":
if (unlockedGuns[2] == true)
return false;
else
{
unlockedGuns[2] = true;
gunsAvailable.Add(allGuns[2]);
return true;
}
case "Rocket Launcher":
if (unlockedGuns[3] == true)
return false;
else
{
unlockedGuns[3] = true;
gunsAvailable.Add(allGuns[3]);
return true;
}
default:
Debug.Log("Weapon Pickup ran into a problem with gunToAdd not matching a predefined string.");
break;
}
return false;
}
One of my friends suggested using a Dictionary with the Gun as a key and the boolean (unlocked) as the value. Since those you can step through. However because Dicts don't show up in the inspector I'd prefer to stick to either an array or a List.
Can anyone help with the code for the mouse wheel scrolling so that it only moves between the guns you've picked up?
Your answer
Follow this Question
Related Questions
Coroutine Waits, But Calls Multiple Times per Update. Is There a Way to Fix This? 1 Answer
How could I add "gravity" to a top-down shooter's bullet, such as in The Binding of Isaac? 0 Answers
2 Issues with my SHUMP game 0 Answers
Can I run C# scripts from Unity on an Ubuntu 19.10 macine? Huge stack of compiling errors. 0 Answers
[common programming question] Custom array returns nothing 2 Answers