- Home /
switching gun on screen with gun you pick up.
Right now i have it so when you run into a gun laying on the ground it gets destroyed so it looks like you picked it up. How now do I have that gun replace the one currently being held on the screen. Thanks
Answer by Jason_DB · Dec 23, 2010 at 02:23 AM
It depends on how your gun works. You might be able to use GameObject.SetActiveRecursively(boolean), which activates or deactivates a GameObject and all of its children (SetActiveRecursively(false) turns it off, SetActiveRecursively(true) turns it on).
For instance you could have an array of weapons, and select a weapon by turning it on and turning all other weapons off. Here's an example where you pass in the index of the weapon you want to select, and it turns that weapon on and all others off.
var weapons : GameObject[];
function selectWeapon(var i : int){ for(var j : int = 0; j <weapons.length; j++){ if(j == i){ weapons[j].SetActiveRecursively(true); } else { weapons[j].SetActiveRecursively(false); } } }
**I just typed this up and haven't actually tested it so apologies for any syntax errors or typos
Answer by Tetrad · Jul 08, 2010 at 02:37 AM
There's probably something here you can look at: http://www.dastardlybanana.com/FPSConstructorWeapons.htm
Answer by Nathan Bennett · Sep 17, 2010 at 06:37 AM
You should have a prefab of the weapons you pick up. Just use an instantiate api, and find out how to add the weapon to be a parent of the player. simple with unity
Your answer
Follow this Question
Related Questions
pick up a gun problem 1 Answer
Mouse locked in center 1 Answer
Gun Rotation Sway 0 Answers
How to pick a weapon of the ground 1 Answer