I am building off of the FPS tutorial script for changing weapons, such as "blah blah blah, change SelectWeapon(2) if 2 is pressed and all that. Then I have the SelectWeapon index code from the FPS tutorial also, but what I did is edit the code to include 5 weapons, not just 2. But the thing is, i dont know how to assign the index variable of the first weapon to SelectWeapon(1) or whatever.
Im using the exact same code from the FPS tutorial, I just dont know to how to set the weapons I have to the index values accordingly. :)
Hey Nick, welcome to UnityAnswers.
The SelectWeapon() function uses the GetChild() function to find the 'children' objects of the object that the SelectWeapon script is attached to. I've added comments to the script below to explain.
As a result, you can't explicitly 'assign the index variable of the first weapon' - rather, you set the weapon to a child of the GameObject that this script is attached to. I'd assume the GetChild() function sorts by name, so you could just name the weapons "0_Fists", "1_Pistol", etc.
Duck's answer to a similar question on 'Weapon Switching' explains how to extend the if/else in the Update() loop, so pressing '3' will select the 3rd weapon, and so on.
Hope this helps!
answered Sep 16 '10 at 03:00 AM