- Home /
Guns and adding guns
I need help adding guns. Like everytime i add a gun it wont show up and if i try to put it next to my player it doesnt do anything. Please i need help if someone could get Teamviewer at teamviewer.com and help me that would be awesome.
No one's going to buy software just to help you in a simple problem :P
you're pretty vague. What do you mean it's not showing up? Does it not show up in the scene? this could be due to small import settings. Is the camera set to render the layer the gun is on? (the gun is just a mesh right?)
Answer by aldonaletto · Feb 04, 2012 at 12:40 AM
If you want to add and select different weapons, the most usual approach is the following:
1- Create an empty object, call it "weapons", child it to the camera and adjust its position and rotation to the place where the weapons will be.
2- Child all possible weapons to the "weapons" object while in the Editor (adjust position and orientation of each one).
3- Attach a selection script like this to the "weapons" object:
function Start(){ SelectWeapon(0); // start with weapon 0 (use -1 for no weapon) }
function Update(){ if (Input.GetKeyDown("1")) SelectWeapon(0); if (Input.GetKeyDown("2")) SelectWeapon(1); if (Input.GetKeyDown("3")) SelectWeapon(2); }
function SelectWeapon(num: int){ for (var i: int = 0; i < transform.childCount; i++){ transform.GetChild(i).gameObject.SetActiveRecursivelly(i == num); } } A similar approach is used in the FPS Tutorial project: download it and follow its manual - you will learn a lot about FPS games.
Your answer
Follow this Question
Related Questions
Attempting to shoot a gun, bullets not colliding. Lots of script inside. 1 Answer
How to make my missle fire angled inward 1 Answer
Space Skybox implementation 5 Answers
Problem with gun/shooting scripting 0 Answers
How to make a gun in unity? 1 Answer