- Home /
Help with switching weapons (Unity 2D)
Hi, I'm trying to create a small turret defense game in Unity 2D. Right now, I'm trying to make the player able to switch between three different firing types while in-game through the use of the number keys.
I've used the script that was shown in here (credit to nastache), and it worked fine when I first implemented it along with some test prefabs to use for it. But on repeated attempts/uses of it, I can no longer switch weapons while testing the game.
The script takes the input on the number keys from 1-3 and changes the 'Current Weapon' variable to the index on the array associated with the number, but the weapon prefab in the player is no longer set to active unless I stop testing the game, and run it again.
Like... if I press 1 to switch to the weapon prefab assigned to Index 0, the Current Weapon variable is set to that, but it does not set that weapon in the player active.
Unity is not giving me any compiler errors or any other such messages, and I don't know how to fix this. Any help would be greatly appreciated.