Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 timothy92 · Mar 09, 2016 at 01:02 PM · unity 5networkingphotonweaponchanging

Photon multiplayer, getting information from photonView.owner

I'm attempting to sync weapons equipped between players, so you can see what everyone is holding, I'm really struggling, I've been trying to figure this out for days, this is my script for syncing and equipping weapons:

 using UnityEngine;
 using System.Collections;
 
 public class InventoryManager : Photon.MonoBehaviour {
 
     public GameObject holder;
     public GameObject[] equippable;
     GameObject player;
     //string localequipped;
     string equipped;
     GameObject playerchanged;
 
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {}
 
     void Update() {
         if (Input.GetKeyDown(KeyCode.Alpha1)) Equip(0,photonView.owner);
         if (Input.GetKeyDown(KeyCode.Alpha2)) Equip(1,photonView.owner);
     }
 
     void Equip(int wepid, PhotonPlayer sender) {
         for (int i = 0; i < equippable.Length; i++)
         {
             equippable[i].SetActive(false);
         }
         equippable[wepid].SetActive(true);
         equipped = equippable[wepid].name;
         GetComponent<PhotonView>().RPC("EquipOther", PhotonTargets.Others, sender);
     }
 
     [PunRPC]
     void EquipOther(PhotonPlayer sender) {
         Debug.Log(sender + "is changing wep");
     }
 
 }

I've passed in the senders photon id/name and from there i want to get its gameobject so i can enable the weapon for all other players on the server, so that they can see the change.

but, i cant seem to find a way to get this to work, only possible way i thought would be to pass the game object through the rpc function, but photon does not support this, please help.

if my system of changing weapon or syncing it is wrong, dont fix it, please help/tell me a better or easier way to do it.

P.s im very new to networking and its hurting my brain.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by SaurabhStudio · Mar 10, 2016 at 09:07 AM

Hello @timothy92 you can try this

 void Equip(int wepid, PhotonPlayer sender) {
                  for (int i = 0; i < equippable.Length; i++)
                  {
                      equippable[i].SetActive(false);
                  }
                  equippable[wepid].SetActive(true);
                  equipped = equippable[wepid].name;
                 PhotonView photonView = PhotonView.Get(this);
 photonView.RPC("EquipOther", PhotonTargets.Others,wepid );
              }
  
      [PunRPC]
      void EquipOther(int wepid)
  {
           equippable[wepid].SetActive(true);
          equipped = equippable[wepid].name;
      }



Comment
Add comment · Show 4 · 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 timothy92 · Mar 10, 2016 at 10:13 AM 0
Share

Thank you for your reply, I had done this in a previous version of my script, but the problem is that this method of doing it sets that weapon equipped for both players, and the main problem is I don't have (or cant think of) a way to differ between players so I can say which player is changing there weapon and share that information with the other users.

Any ideas?

Thanks, $$anonymous$$thy.

avatar image SaurabhStudio · Mar 11, 2016 at 06:30 AM 0
Share

This script is attached to Player or this is common between players? If it is common then you can give different name to your player. and can pass that name in RPC call. And you can check the name at receive call. if(gameObject.name == "$$anonymous$$yPlayer") { // your code }

avatar image timothy92 SaurabhStudio · Mar 11, 2016 at 01:50 PM 0
Share

Hmm, seems do-able, the script is common, how would I go about giving each player a unique .name, usernames perhaps?

avatar image timothy92 SaurabhStudio · Mar 11, 2016 at 01:51 PM 0
Share

I'll think of something, thanks for your help man :P really appreciate it.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

This is giving an error for the other client and cannot hit other client. 1 Answer

Question regarding unity mobile multiplayer game 0 Answers

Using Photon View To Sync "WheelCollider" how? 0 Answers

Car Syncing Problems with Photon 0 Answers

Unity 5.6 Webgl Photon Spawn Error 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