|
Hi I'm making a first person shooter where the player can hold, use and switch between two weapons. I want to be able find a weapon on the ground, pick it up and switch it out with one of my weapons and drop that weapon and use the new weapon. I could really use some help on a semi easy way to do this.
(comments are locked)
|
|
What you could first do is create an array for the player's weapons (in a weapon control script similar to the one in the FPS Tutorial). That would allow you to have two easily switched out weapons and leave the option the increase the number of weapons easily. This script would manage the weapons as well as tell them when to fire/reload and would be added to the main camera of your player (the weapons themselves would be children of the main camera). The weapon scripts would have functions called "selectWeapon" and "deselectWeapon" to turn them on or off.
}
What you could then do is create a "selectableWeapon" script, which would only need to have one variable (the weapon that it references). You would put this script on the weapon model in the environment and then tag it as something like "pickupAble" (so that when the player looked at the weapon lying on the ground they can pick it up).
You would just need to have every possible weapon be attached to the main camera (all but two of them being deactivated), so that when the player selects a gun off the ground that weapon would activate one of the player's weapons. Here's a "selectweapon" script that you could put on the main camera to actually switch the weapons out.
These are trimmed down scripts from my game, so they would require some tweaking to work in another one. Again, though, a lot of this is derived from the FPS Tutorial if you want to look at that. Also, sorry if this is too long or too specific. This great help thanks. I was also wondering how to make the weapon on the ground disappear after you picked it up the spawn back later?
Mar 23 '10 at 02:17 AM
Joe 3
You could probably deal with that by activating and deactivating the model (by turning off the renderers)
Mar 23 '10 at 08:28 PM
Jason_DB
Be sure to also turn off the pickup collider, not just the shader, so you dont randomly pick stuff up that isnt "there". you could also have it physically spawn your gun prefabs, but I have no idea how to do that.
Apr 19 '10 at 11:26 PM
user-1794
this doesn't work
May 09 '11 at 04:30 PM
bubblegumsoldier
The code is just examples pulled from my own system. It won't work as it is, but the design works.
May 09 '11 at 09:44 PM
Jason_DB
(comments are locked)
|
|
Can u help me with the weapons pack from you? , its says that the Reload input and the pickup input is missing how do i add it? i download your pack
(comments are locked)
|
