- Home /
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:
-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.
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.