Okay, you have 3 mains things going on here:
1- Actual Object of your weapons (eg: assault rifle, pistol, and frag)
2- Script that holds the weapons
3- the user interface - so a heads up display (Unity call it a GUI)
Step one would be something like this:
Drag your model of your assault rifle onto your scene, and place it into a empty object and call it assault rifle. Then, make sure your model is set to 0,0,0 axis within the empty object. Place your assault rifle into your camera within your character controller.
So you should have something like this in your hierarchy: FirstPersonController > MainCamera > Assault Rifle > Model (remember: with the model being at 0,0,0)
Next, move your Assault Rifle (the empty object) so it looks like your character is holding it correctly and is on screen.
Do this repeatedly with your pistol ... and your frag? (maybe having a model of an arm holding a frag??)
So you should have 3 objects under your camera: Assault rifle, pistol and frag all in the correct position.
-- Now time for the script (Java Script)--
This is basically going to be an inventory. So you want something like this:
var assaultRifle : GameObject;
var pistol : GameObject;
var frag : GameObject;
-- or if you want an array (which is slightly more complicated):
var weapons : GameObject[];
By the way - call this script WeaponInventory or something and drag it onto your Camera. Then, drag your assault rifle game object onto the var : assaultRifle in the Inspector. Or, if you did the array, drag it on that ... for now, I wont be using the array.
So like I said: drag your weapons corresponding to the variables we just made.
Go back to your script and add a start function:
function Start(){
//we want to define our first choice of weapon - this case will be the assault rifle
assaultRifle.gameObject.SetActiveRecursively(true);
pistol.gameObject.SetActiveRecursively(true);
frag.gameObject.SetActiveRecursively(true);
//this will deactivate the pistol and frag, and leave on the assault rifle
}
Next is to change the weapons depending on the Key Input:
function Update(){
if(Input.GetKeyDown("1")){
//assault key
killAll();
assaultRifle.gameObject.SetActiveRecursively(true);
}
if(Input.GetKeyDown("2")){
//pistol key
killAll();
pistol.gameObject.SetActiveRecursively(true);
}
if(Input.GetKeyDown("3")){
//frag key
killAll();
frag.gameObject.SetActiveRecursively(true);
}
}
function killAll(){
assaultRifle.gameObject.SetActiveRecursively(false);
pistol.gameObject.SetActiveRecursively(false);
frag.gameObject.SetActiveRecursively(false);
}
This is kind of rushed but it gets the job done. If you want animation of the character 'putting' the weapon down, and then selecting his next one this you just do a play.animation.
Hope that kinda helps.
totally works, really cool man :)
– eeveelution8whoa i never thought of it that way
– knuckles209cp