Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jimmycrazyskills · Feb 14, 2014 at 12:55 AM · playerweaponhow toswap

How to swap weapons easily?

Hi,what would be the best way of swapping weapons on a player? , for example I could have every weapon already a child of the player and only render one at a time , but I'm guessing this is extremely inefficient. I have attached a picture(epic paint skills ;) ) to try and show what I mean , sorry if this question isn't specific enough! alt text

question picture.png (31.4 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Feb 14, 2014 at 12:57 AM 1
Share

Your first approach is oft used. Another approach is to create a "hook" empty gameObject on the hand and based on player Input/actions to parent a new weapon to that and remove the other.

avatar image jimmycrazyskills · Feb 14, 2014 at 01:06 AM 0
Share

hmmm ok , thanks for your help , if anyone else has anything to add please do!

avatar image KrisJulio · Feb 14, 2014 at 01:59 AM 0
Share

Yes The first comment is good. But ins$$anonymous$$d of removing the gameObject of the Gun. You can just show and hide. Just position all the possible weapon. And show whenver the user want's it to show

avatar image AdamScura · Feb 14, 2014 at 02:18 AM 0
Share

I don't think it matters which way you do it. Just keep in $$anonymous$$d there is a slight performance penalty for creating and destroying objects, but that should not make any difference unless you're optimizing for mobile.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by 4u2fap · Feb 14, 2014 at 04:44 AM

well if you have all the weapon as a child of the camera (assuming you are making an fps) attach a script to the camera. then you can create a list of GameObjects for your gun that is attach and then enable or disable them.

for example:

 var gun1 : GameObject;
 var gun2 : GameObject;
 
 function Start() {
 gun1.gameObject.SetActive(true);
 gun2.gameObject.SetActive(false);
 }
 
 function Update(){
     if (Input.GetKeyDown("1")){
     gun1.gameObject.SetActive(true);
     gun2.gameObject.SetActive(false);
     }
     else if (Input.GetKeyDown("2")){
     gun1.gameObject.SetActive(false);
     gun2.gameObject.SetActive(true);
     }
 }

this scrip is not the best way to do it and has not been tested so they may be some issues with it but i think you get the point of what im saying.Dont forget to add your inputs 1 and 2 by going into edit -project settings - Input

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yerp_1234567890 · Jan 10 at 05:54 PM 0
Share

this did not work for me

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to detect if something is added to PlayerPrefs? 2 Answers

I am making a Call of Duty type game, how can I make the people settings just like call of duty? 2 Answers

Player Swap 1 Answer

Why is my enemy stopping before it reaches the player? 1 Answer

Photon - Change others player health problem 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges