Unity Photon Sync Coins for all Players

576 Views Asked by At

I have an problem on Synchronizing an Integer. When I collect with the first Player (The First Connected with the room) a Coin Than the Text(UI) of the Coins are Changing on all Clients but if I collect with an other Player it Only Change for hisself.

How Can I fix this Problem? This is the Code for Synchronizeing the Coins:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoneyManager : MonoBehaviour{
    public int Coins;
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
        if(stream.isWriting){
            stream.SendNext(Coins);
        }else if(stream.isReading){
            Coins=(int) stream.ReceiveNext();
        }
    }
}

This is the Code for changing The Text of the UI Element

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UiManager : MonoBehaviour{
    public Text Coins;

    void FixedUpdate(){
        Coins.text="  Coins: "+GameObject.Find("MoneyManager").GetComponent<MoneyManager>().Coins;

        //some Other Code for other Things...
    }
}

If you need some other things to know just ask.

0

There are 0 best solutions below