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
1
Question by stoneproductions · Oct 13, 2014 at 02:52 PM · photonrpcweaponswitching

PhotonNetwork Switching Weapons (network sync)

I am making a FPS Shooter game with the help of PUN (learning it). Now i have made a script "WeaponManager" where i get the Input and sending a RPC (Photon View is on the Weapon GameObject, which is a Child of the PlayerController GameObject) to change the Weapon. My problem is, that if anyone wants to change his weapon, for example scrolls up, then everyone's weapon get changed. I know where the problem is, but i do not know how to solve it. I want that only "my" weapon gets changed, but everyone sees is.

 void Update () {
 
         Debug.Log (currentWeaponName);
             
         if (Input.GetAxis ("Mouse ScrollWheel") < 0) {
             if (currentWeapon + 1 <= maxWeapons) {
                 currentWeapon++;
             } else {
                 currentWeapon = 0;
             }
             GetComponent<PhotonView>().RPC("SelectWeapon", PhotonTargets.All, currentWeapon);
             
         } else if (Input.GetAxis ("Mouse ScrollWheel") > 0) {
             if (currentWeapon - 1 >= 0) {
                 currentWeapon--;
             } else {
             currentWeapon = maxWeapons;
             }
             GetComponent<PhotonView>().RPC("SelectWeapon", PhotonTargets.All, currentWeapon);
             
         }
             
         if (Input.GetKeyDown (KeyCode.Alpha1)) {
             currentWeapon = 0;
             GetComponent<PhotonView>().RPC("SelectWeapon", PhotonTargets.All, currentWeapon);
             
         }
             
         if (Input.GetKeyDown (KeyCode.Alpha2)) {
             currentWeapon = 1;
             GetComponent<PhotonView>().RPC("SelectWeapon", PhotonTargets.All, currentWeapon);
             
         }
             
         if (Input.GetKeyDown (KeyCode.Alpha3)) {
             currentWeapon = 2;
             GetComponent<PhotonView>().RPC("SelectWeapon", PhotonTargets.All, currentWeapon);
             
         }
             
         if (Input.GetKeyDown (KeyCode.Alpha4)) {
             currentWeapon = 3;
             GetComponent<PhotonView>().RPC("SelectWeapon", PhotonTargets.All, currentWeapon);
             
         }
 
         if (currentWeapon == maxWeapons + 1) {
             currentWeapon = 0;
         }
         if (currentWeapon == -1) {
             currentWeapon = maxWeapons;
         }
             
     }
 
     [RPC]
     void SelectWeapon(int index){
         for (int i = 0; i < transform.childCount; i++) {
             if(i == index){
                 transform.GetChild(i).gameObject.SetActive(true);
                 currentWeaponName = transform.GetChild(i).gameObject.name;
             }
             else{
                 transform.GetChild(i).gameObject.SetActive(false);
             }
         }
     }
 



The Weapons GameObject (on which the PhotonView and the WeaponManager Script is applied) has four childs (for four Weapons) which I activate / deactivate in the Select Weapon function.

Comment
Add comment · Show 1
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 Barry100 · Dec 14, 2014 at 08:12 PM 0
Share

hey did you ever get this fixed? I have EXACTLY the same problem!

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by stoneproductions · Apr 03, 2015 at 12:21 PM

I actually figured it out! Sorry that I did not post it already. You have to set the WeaponManager Script Component to active only for "your" player. Then it works perfectly fine. So just set it to false in the prefab and activate it when you spawn your player.

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 sambid123sameer · Jul 22, 2017 at 06:47 PM 0
Share

You are a life saver Thanks

avatar image
0

Answer by Barry100 · Dec 14, 2014 at 10:04 PM

if anyone reads this.. i thin the problem is that when the reciever gets the RPC that it dosnt know what guy needs his weapon changed so as it is never told who to change.. so it changes everything as this is what its being told.. i am thinking that the RPC needs to identify the ID of the photon object and then only change thats weapon.. well at least that is what I am trying to get workin right now BUT i dont know how to get the Senders Photon ID from the RPC!!

I think as soon as i work this out i will have this working as intended.. if anyone can help then that would be great!

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 ManitoBart · Apr 02, 2015 at 07:38 PM 0
Share

Hi, Do you find solution, because I have exactly the same problem.

avatar image
0

Answer by Promonster · Jul 29, 2016 at 12:32 PM

Can I get your code;WeaponManager? Now I'm studying this part.. please

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

Answer by juraj123 · Apr 15, 2018 at 12:17 PM

Please, how to do it, if Im using numbers - if I press 2, my pistol will setActive(true) and all will see it? Please help

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

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

8 People are following this question.

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

Related Questions

Photon - Change others player health problem 0 Answers

How to swap purchased weapons over Photon Network? 1 Answer

Weapon Switch System for Gear VR Controller 0 Answers

I'm trying to generate a random key and share it with other players when they join the game i'm using PUN. it's not working please help! 0 Answers

How does the synchronization work with Photon Pun RPCs and stream.IsWriting? 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