Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Coder156 · Jun 20, 2014 at 03:56 AM · c#multiplayerfpsweaponchanging

How do I change weapons with Photon (FPS) C#

I'm following a tutorial (albeit with some add-ins, though I don't think any would be affecting this) on YouTube by Quill18Creates, the first episode being entitled: Multiplayer FPS in Unity 3d, Part 1: Introduction & Project Setup. Here's a link: http://www.youtube.com/watch?v=AIgwZK151-A

The tutorial is currently in progress, and he has not covered 'weapon switching', so I figured I'd ask the question here (I'm too impatient to wait ^_^).

The way Quill 18 has his system work:

  1. -Each weapon prefab has a 'weapon data' script attached to it. The weapon data script only has floats and ints attached to it, such as range, damage, rate of fire, etc.

  2. When firing, the PlayerShooting script uses:


"weaponData = gameObject.GetComponentInChildren();"


the rest of the script refferances parts, such as "`weaponData.damage`", etc.

Because of this, the best way I can think of to change weapons would be to use the "PhotonNetwork.Instantiate(yadda yadda yadda);" command every time you switch a weapon. Then when you switch to the next weapon, you destroy the previous weapon.

I have tried this, and several other ways. I'm not a very experienced programmer, so I probably got the code wrong, but I was: 1) unable to get the component to destroy itself when I tried to switch weapons, and 2) unable to get the PlayerShooting script to read the WeaponData script from the instantiated weapon.

If someone can please tell me what I'm doing wrong, or preferably, post some code that works, I would really appreciate it. If I've left out any important information, please let me know. Most of it should be in the video series, though.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

When a host player changes his weapon all players get switched to it 1 Answer

How to connect to hosted scene (Multiplayer) 2 Answers

FPS Footstep Audio Plays Too Quickly 1 Answer

Picking up objects wont work on server 0 Answers

Change player control to a target model (FPS) 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