Client cant update variable
Options
When Master connects in room text in Text become "1"
When Client connects it should be "2", but when client connects nothing happens.
When Client connects it should be "2", but when client connects nothing happens.
using UnityEngine;
using System.Collections;
public class test1 : Photon.MonoBehaviour {
public bool AutoConnect = true;
public byte Version = 1;
private bool ConnectInUpdate = true;
public virtual void Start() {PhotonNetwork.autoJoinLobby = false;}
public virtual void Update() {
if (ConnectInUpdate && AutoConnect && !PhotonNetwork.connected) {
Debug.Log("Update() was called by Unity. Scene is loaded. Let's connect to the Photon Master Server. Calling: PhotonNetwork.ConnectUsingSettings();");
ConnectInUpdate = false;
PhotonNetwork.ConnectUsingSettings(Version + "."+Application.loadedLevel); } }
// to react to events "connected" and (expected) error "failed to join random room", we implement some methods. PhotonNetworkingMessage lists all available methods!
public virtual void OnConnectedToMaster() {
if (PhotonNetwork.networkingPeer.AvailableRegions != null) Debug.LogWarning("List of available regions counts " + PhotonNetwork.networkingPeer.AvailableRegions.Count + ". First: " + PhotonNetwork.networkingPeer.AvailableRegions[0] + " \t Current Region: " + PhotonNetwork.networkingPeer.CloudRegion);
Debug.Log("OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room. Calling: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom(); }
public virtual void OnPhotonRandomJoinFailed() {
Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
RoomOptions roomOptions = new RoomOptions ();
roomOptions.maxPlayers = 2;
PhotonNetwork.CreateRoom(null, roomOptions, null); }
// the following methods are implemented to give you some context. re-implement them as needed.
public virtual void OnFailedToConnectToPhoton(DisconnectCause cause) {
Debug.LogError("Cause: " + cause); }
public void OnJoinedRoom() {
GameObject _text = GameObject.Find ("Text");
if (!PhotonNetwork.isMasterClient) {
_text.GetComponent ().DoHeroBinding (1);
} else {
int e = _text.GetComponent ().i;
_text.GetComponent ().DoHeroBinding (e+1); }}}
using UnityEngine;See, nothing happens:
using UnityEngine.UI;
using System.Collections;
public class textUpdate : Photon.MonoBehaviour {
public int i= 0;
public void DoHeroBinding(int PlayerId){
photonView.RPC ("Bind", PhotonTargets.AllBuffered, PlayerId); }
[RPC]
public void Bind(int PlayerId, PhotonMessageInfo info){
i = PlayerId;
gameObject.GetComponent ().text = i.ToString (); }}
0