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 SPOTNINJADUD7890 · Oct 28, 2016 at 05:21 AM · c#unity5photonmultiplayer-networking

This is only activating the hat locally or an all clients or no clients.

I made this code to try to get my character customization form my silly little multiplayer game, but this does not activate the hat if the other client has their hat set to on. ignore the monical and parrot.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class CosAct : MonoBehaviour {
     public PhotonView photonView;
     public int hatTrue = 0;
     //public int monicalTrue = 0;
     //public int parrotTrue = 0;
 
     void Update(){
         photonView = this.transform.GetComponent<PhotonView> ();
         hatTrue = PlayerPrefs.GetInt ("Hat");
         //monicalTrue = PlayerPrefs.GetInt("Monical");
         //parrotTrue = PlayerPrefs.GetInt("Parrot");
     if(hatTrue == 1){
             Debug.Log ("set hat on");
             ActHat();
         }else{
             return;
         }
     //if(monicalTrue == 0){
     //    ActMonical();
     //    }else{
     //        return;
     //    }
     //if(parrotTrue == 0){
     //    ActParrot();
     //    }else{
     //        return;
     //    }
     }
     void localhatlayer(){
         if(photonView.isMine){
             this.transform.FindChild ("Hat").FindChild("botcy").gameObject.layer = 11;
             this.transform.FindChild ("Hat").FindChild("topcy").gameObject.layer = 11;
         }
     }
     [PunRPC]
     void ActHat(){
         transform.FindChild("Hat").gameObject.SetActive(true);
         localhatlayer ();
     }
     void ActMonical(){
         transform.FindChild("Monical").gameObject.SetActive(true);
     }
     void ActParrot(){
         transform.FindChild("Parrot").gameObject.SetActive(true);
     }
 }
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 ChristianSimon · Nov 01, 2016 at 09:27 AM 0
Share

There are multiple problems with your provided code. void ActHat() has a RPC attribute but is never called as RPC, which in this case might be okay. Secondly you are storing the current 'hat' in the PlayerPrefs. This might also be okay, but you are never changing the value (maybe it is set in some other class), so the hat stays the same. Also when changing the hat you have to disable the previous active one, since I guess they should not be stackable. Another thing is that you want to synchronize the player's look once the hat is changed, this is also not present in your provided code.

What you want to have is more or less the following flow: Update() -> photonView.is$$anonymous$$ine -> locally change the hat -> tell others somehow, that you changed your hat

The last step can be done by using RPCs, RaiseEvents or OnPhotonSerializeView, which might be the best way in this case.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SPOTNINJADUD7890 · Nov 04, 2016 at 06:52 PM

Thanks for the reply. I am changing the hat playerpref on another screen. I know how to change the hat localy. I dont really know what you mean by tell others somehow that you changed your hat because if i knew how to do that i wouldnt really be asking the question. But ty anyway if you could give a bit of sample code 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 ChristianSimon · Nov 07, 2016 at 09:12 AM 0
Share

For example using a RPCs function call. This can be something like PhotonView.RPC("SomeFunction", PhotonTargets.Others, photonViewId, newHatId);. On receiving side, check if photonViewId matches the current game object in order to apply changes to the correct object. Then change the hat by using the received ID of the hat or whatever identifier you are using for this scenario. You might want to check on the documentation again and also take a look at the Photon$$anonymous$$essageInfo received on RPC call and see if this might help you, selecting the correct game object.

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

238 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

PUN - Choose random Hero for player 0 Answers

Unity Photon Transform movement applying to opposite prefab 1 Answer

How to instantiate prefabs list in turn photon 1 Answer


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