Question by
DanChirtoaca · Mar 18, 2016 at 02:37 AM ·
networkingrpclobby
ClientRpc s are not called
Rpc's are not called when using NetworkLobbyManager instead of NetworkManager. It seems to work properly with the latter, but when I switch to the former, only [Command]'s are called, [ClientRpc]'s are somehow skipped. I am using Unity 5.1.0f3.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Player : NetworkBehaviour {
public Deck deckPrefab;
Deck deck;
// Use this for initialization
void Start () {
if (isLocalPlayer) {
if (!isServer) {
GameObject.FindWithTag("MasterDeck").SetActive(false);
}
(this.deck = (Deck)Instantiate (deckPrefab)).Constructor();
this.deck.transform.SetParent (this.transform);
this.name = "LocalPlayer";
}
}
[ClientRpc]
public void RpcUpdate(int networkIdentity) {
UpdatePlayerCard (networkIdentity);
}
void UpdatePlayerCard(int networkIdentity) {
if (isLocalPlayer ) {
if (this.netId.Value == networkIdentity) {
this.deck.SetNextCard();
}
}
}
[Command]
public void CmdUpdate(int[] card, int symbol, int networkIdentity) {
Deck mdeck = GameObject.FindWithTag("MasterDeck").GetComponent<Deck>();
if (mdeck.ContainsSymbol(symbol)) {
mdeck.SetTopCard(card);
RpcUpdate(networkIdentity);
}
}
// Update is called once per frame
void Update () {
if (isLocalPlayer && Input.GetMouseButtonDown(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100)) {
int symbol = 0;
if (int.TryParse(hit.transform.gameObject.name, out symbol)) {
CmdUpdate(this.deck.GetTopCard(), symbol, (int)this.netId.Value);
}
}
}
}
}
Comment
Answer by Alberto-Mastretta · Mar 24, 2016 at 05:03 PM
I'm having a similar problem. In my scenario, I get clientRPC calls working properly whenever I enter the lobby and go directly into my game scene, but if I exit the lobby and enter a new one (either creating one or joining one), they stop working. It only happens if I ever exit a lobby.