Help Me!

Options
Hello, dear users of Photon Unity Network! I really like to study it. But I ran into a problem. To start, I will describe what I did:

I created a cube by clicking on which points are increased by 1.

The problem is that in the first window, if I click on the cube - the value of both windows is increased by 1.
But if I do this in the second open window - the value of the second window only increases by 1.

I want to do MMORPG and it's important for me to synchronize the health of all the mobs in all windows.

I hope you understood me correctly and will help me ... Pliz!

Ah, yes ... Code:

The cube itself:

using UnityEngine;
using System.Collections;

public class ClickerBeh: Photon.PunBehaviour, IPunObservable {

public int hp = 0;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}

void OnGUI () {
GUI.Box (new Rect (10, 10, 100, 20), "" + hp);
}

void OnMouseDown () {
hp + = 1;
}

public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
{

stream.Serialize (ref hp);

}
}

His Spawner:

using UnityEngine;
using System.Collections;

public class Spawn: Photon.PunBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}

public override void OnJoinedRoom ()
{
PhotonNetwork.InstantiateSceneObject ("Enemy", transform.position, Quaternion.identity, 0, null);
}
}

Comments

  • Hi @Pub,

    modifications to an object can only be synchronized properly when applied by its owner. So in your case the first player (who is the owner of the object) clicks on the object in order to increase some value. This is then halfway synchronized by using the OnPhotonSerializeView function. Please note that only the owner of the object can successfully write data to the stream. When now your second client clicks on the object in order to increase a value, this will be processed locally but that client can apply this modification on other clients. At least not in that way you have above.

    To get a better understanding on how the synchronization with OnPhotonSerializeView functions, I would recommend you taking a look at the PUN Basics Tutorial from the PUN package as well as related documentation page.
  • Pub
    Options
    Christian_Simon, Thanks! Even if so, can I somehow contrive and realize my plan?
  • There are always possibilities to get things working. :)

    For your example you can use RPCs (Remote Procedure Calls). This way, also clients, who are not the owner of the object, can somehow modify values. Therefore you can invoke a RPC calls whenever the object gets clicked. If this happens, a message is sent either to all or to selected clients, who will process a certain function on the game object. There is again a documentation page which describes how this is working best. So I recommend you taking a look at the RPCs and RaiseEvent documentation page.
  • Pub
    Pub
    edited March 2018
    Options
    Christian_Simon, Thanks so much! You save me! I want to be your friend! :)