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 KuPAfoo · Dec 04, 2013 at 01:15 AM · networkingphotonprivate

Photon Prefab specific bool

So, I'm trying to send render states of specific objects equipped to my player. Here is my current code: using UnityEngine; using System.Collections;

 public class sheildWeild : MonoBehaviour {
     private bool weild;
     public Renderer rens;
     //GameObject SHEILD;
     private PhotonView myPhotonView;
     
     public static string setRenderer = "SetRenderer";
     // Use this for initialization
     void Start () {
         myPhotonView = this.GetComponent<PhotonView>();
     weild=true;
         Debug.Log (weild);
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKeyDown(KeyCode.BackQuote))
         {
             if(weild==false)
             {
             this.myPhotonView.RPC("SetRenderer", PhotonTargets.AllBuffered, true);
                 weild=true;
             }
             else
             {
                 this.myPhotonView.RPC("SetRenderer", PhotonTargets.AllBuffered, false);
                 weild=false;
             }
         }
         Debug.Log (weild);
     }
     
     [RPC]
     void SetRenderer(bool weild){
         this.renderer.enabled=weild;
     }
     
 }

This code allows all clients to see when a player's shield is wielded or not. The problem is, all players on their client weild/unweild their shield. Only the client's player should change render state.

alt text

the picture above displays the left client having a sheathed status, while the client to the right has wielded status. As the left client was the last to affect the status of the shield's renderer.enabled property, he has not only affected his own shield on the other client's view, but all shields in game.

How can I make the Boolean weild only affect the active client's objects?

12-3pun.jpg (71.8 kB)
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 KuPAfoo · Dec 04, 2013 at 01:21 AM 0
Share

I was attempting to play with public Renderer rens;

Now i'm thinking maybe I need to use public Renderer rens[];

and possibly pull the playerID into the array for location?

I'm not sure how to pull the playerID or if this would even work

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CiberX15 · Dec 04, 2013 at 01:43 AM

I did not write this but I believe it is what you are looking for. What it does is check if the object in question is remote or local and enables and disables scripts as necessary. To make it work simply fill the arrays with the scripts you want to be enabled/disabled and it should do the rest.

 using UnityEngine;
 using System.Collections;
  
 public class PlayerNetworkInit : MonoBehaviour
 {
     [SerializeField] Behaviour[] behavioursEnabledOnLocalClientsOnly;
     [SerializeField] Behaviour[] behavioursEnabledOnRemoteClientsOnly;
     [SerializeField] GameObject[] gameObjectsEnabledOnLocalClientsOnly;
     [SerializeField] GameObject[] gameObjectsEnabledOnRemoteClientsOnly;
  
     void OnNetworkInstantiate( NetworkMessageInfo msg ) 
     {
         if( !networkView.isMine )
         {
             name += "(remote)";
         }
         foreach( Behaviour behaviour in behavioursEnabledOnLocalClientsOnly )
         {
             behaviour.enabled = networkView.isMine;
         }
         foreach( Behaviour behaviour in behavioursEnabledOnRemoteClientsOnly )
         {
             behaviour.enabled = !networkView.isMine;
         }
  
         foreach( GameObject go in gameObjectsEnabledOnLocalClientsOnly )
         {
             go.SetActive(networkView.isMine);
         }
         foreach( GameObject go in gameObjectsEnabledOnRemoteClientsOnly )
         {
             go.SetActive(!networkView.isMine);
         }
     }
 }
Comment
Add comment · Show 8 · 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 KuPAfoo · Dec 04, 2013 at 02:18 AM 0
Share

I think this question got 'vanished' by superiors... I don't quite understand your directions

This should be equipped to my prefab? or the object i'm changing states on?

behaviorsEnabledOnLocalClientsOnly should be changed to "sheildweild"?

avatar image CiberX15 · Dec 04, 2013 at 03:05 AM 0
Share

It should be on the prefab, added as a script. In the editor it will have four different arrays that can store scripts. Drag the scripts that are already on the prefab onto the the monobehavor arrays.

On the client side what happens is you get several identical entity's all looking for the same inputs. What this does is check if the object originated on the particular client and if not stops those scripts from executing.

$$anonymous$$ind you this means that if there is part of your script that should be firing regardless of whether it is local or remote, then you will either need to move it to a separate script or canabalise the above script.

networkView.is$$anonymous$$ine is the major workhorse of the script. it returns a bool based on wither its gameobject is local or remote.

avatar image KuPAfoo · Dec 04, 2013 at 03:13 AM 0
Share

Thank you! I will be trying this asap!

I will post back and let you know my progress. THAN$$anonymous$$ YOU AGAIN for looking into this!

avatar image KuPAfoo · Dec 04, 2013 at 04:26 AM 0
Share

Okay... I got the local set up and it appears to be affecting the opposite player on the other player's client.

on my client my character changes state, but on the other client their character changes state on $$anonymous$$Y keypress alt text

edit: SS not showing?

This only appears to be giving both clients lag, all protocalls follow the previous setups :\

I've tried 3 different script influences such as renderer.enabled = true;

 if(photonView.is$$anonymous$$ine)
 myphotonview.renderer.enabled = true;
 
 if(!photonview.is$$anonymous$$ine)
 this.renderer.enabled = true;
 
 I'm beginning to think the keypress has something to do with it
avatar image CiberX15 · Dec 04, 2013 at 02:35 PM 0
Share

Well the other client should not be able to detect your remote key-presses. However if you have a network view set to sync the scripts it may be detecting it on your client then syncing the remote script. I think you can change that in the network view?

Show more comments
avatar image
0

Answer by KuPAfoo · Dec 05, 2013 at 10:41 PM

I feel dumb... the answer was to make my Update() private and also my setRenderer() private. Well... I learned a lot of stuff in this 80 lines or so of code. I hope the papertrail can help someone else!

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

17 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

Related Questions

Photon shot collision 1 Answer

Server receives RPCs after RemoveRPCs and Destroy 0 Answers

Assign Prefab to script as Code? 2 Answers

Unity networking tutorial? 6 Answers

Player names all displayed as local player photon 2 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