Search Unity

Syncing Info from Networked Remote Player to Local

Discussion in 'Multiplayer' started by programmrzinc, Jul 24, 2015.

  1. programmrzinc

    programmrzinc

    Joined:
    May 29, 2011
    Posts:
    79
    I have a plane game, where position info and other metrics are synced from the local player to their remote player on other clients, but how to I sync info from the remote player back to the sam local player, such as health? Here's a snippit of what I have, but its not syncing as is should

    Code (CSharp):
    1.  public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    2.     {
    3.  
    4.         //Debug.Log("View is Serialized");
    5.  
    6.         if (stream.isWriting)
    7.         {
    8.             //Our player
    9.  
    10.             stream.SendNext(transform.position);
    11.             stream.SendNext(transform.rotation);
    12.             stream.SendNext(Input.GetAxis("Fire") ==-1f);
    13.             stream.SendNext(weapon.CurrentWeapon);
    14.             stream.SendNext(damage.HP);
    15.            
    16.         }
    17.         else
    18.         {
    19.             //someone else's player
    20.  
    21.             realPosition = (Vector3)stream.ReceiveNext();
    22.             realRotation = (Quaternion)stream.ReceiveNext();
    23.             realFiring = (bool)stream.ReceiveNext();
    24.             realWeapon = (int)stream.ReceiveNext();
    25.             realDamage = (int)stream.ReceiveNext();
    26.            
    27.  
    28.         }
    29.  
    30.     }
    31.     void Update()
    32.     {
    33.         if (!photonView.isMine)
    34.         {
    35.            
    36.             transform.position = Vector3.Lerp(this.transform.position, realPosition, Time.deltaTime * 15);
    37.             transform.rotation = Quaternion.Lerp(this.transform.rotation, realRotation, Time.deltaTime * 30);
    38.             weapon.CurrentWeapon = realWeapon;
    39.          
    40.             if (realFiring)
    41.             {
    42.                 weapon.LaunchWeapon();
    43.             }
    44.              
    45.         }
    46.         else
    47.         {
    48.              damage.HP = realDamage;
    49.             print(realDamage);
    50.         }
    51.     }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    You are not contrained to send position and damage. You can use more than one PhotonView as well. So you could have a PhotonView, which is belonging to the Master Client, which sends the state of everyone (HP, etc)...
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
  4. programmrzinc

    programmrzinc

    Joined:
    May 29, 2011
    Posts:
    79
    Hmmm. I never thought to use customProps. I'll give it a whirl, and tell you the results!