Syncing Player Colors
Options
Baenor
✭
Hi guys, i'm working with my multiplayer game.
I created with the 4.6 UI a system that let you choose the armor color that you like. The fact is now that i dont know how to sync every player color over the network.
I was tryng to work with RPC, by creating a function, in my NetworkCharacter script that is "followed" by PhotonView component on the player prefab :
At this moment, the color is the same for every client. Every istance of the game has the color that they choose initially....
Any suggestions?
Thanks
I created with the 4.6 UI a system that let you choose the armor color that you like. The fact is now that i dont know how to sync every player color over the network.
I was tryng to work with RPC, by creating a function, in my NetworkCharacter script that is "followed" by PhotonView component on the player prefab :
using UnityEngine; using System.Collections; //we use photon.mono because there is a built-in photonview object public class NetworkCharacter : Photon.MonoBehaviour { Vector3 realPosition = Vector3.zero; Quaternion realRotation = Quaternion.identity; Vector3 velocity = Vector3.zero; Color currentColor; GameObject armor; //that's the gameObject child of PlayerPrefab that has the color changed Animator anim; // Use this for initialization void Awake () { armor = transform.Find ("Armatura").gameObject; //Finds it on the hierarchy currentColor = armor.renderer.material.color; anim = GetComponent<Animator> (); } void Start(){ photonView.RPC("SetColor",PhotonTargets.AllBuffered,null); //Set color } // Update is called once per frame void Update () { if (photonView.isMine) { //do nothing } else { //from where we are to actually where we should be transform.position = Vector3.Lerp(transform.position,realPosition,0.1f)+ velocity*Time.deltaTime; transform.rotation = Quaternion.Lerp(transform.rotation,realRotation,10*Time.deltaTime); } } void OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info){ if (stream.isWriting) { //this is OUR player. We need to send our actual position to the network stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(rigidbody.velocity); stream.SendNext(anim.GetBool("IsWalking")); stream.SendNext(anim.GetBool("IsRunning")); } else { //this is someone else's player. WE Need to recieve the position and update //our versione of he player realPosition = (Vector3)stream.ReceiveNext(); realRotation = (Quaternion)stream.ReceiveNext(); velocity = (Vector3)stream.ReceiveNext(); anim.SetBool("IsWalking", (bool)stream.ReceiveNext()); anim.SetBool("IsRunning",(bool)stream.ReceiveNext()); } } [RPC] public void SetColor(){ if(photonView.isMine) armor.renderer.materials[0].color = currentColor; } }
At this moment, the color is the same for every client. Every istance of the game has the color that they choose initially....
Any suggestions?
Thanks
0
Comments
-
Please always post links if you double-post in various forums. Thanks.
I answered in Unity's forum.
http://forum.unity3d.com/threads/syncin ... un.280636/0