- Home /
Question by
Amalah · Feb 05 at 01:32 AM ·
c#multiplayermirrorclient-server
Mirror not sending game object data to client
I'm making a simple card game and trying to get Mirror to display all the cards and their properties on the board. I've managed to get card placing and moving working across the clients, but when drawing cards from the deck, the scriptable object properties aren't being replicated on the client. This is what I've attempted:
[Command]
public void CmdDealCards() {
Card[] allCards = Resources.LoadAll<Card>("Assets");
GameObject cardObject = Instantiate(allCards[0].prefab);
PlayableCard playableCard = cardObject.GetComponent<PlayableCard>();
playableCard.card = allCards[0];
playableCard.Init();
cardObject.transform.SetParent(PlayerHandZone.transform, false);
NetworkServer.Spawn(cardObject, connectionToClient);
RpcShowCard(cardObject, "Dealt");
}
[ClientRpc]
void RpcShowCard(GameObject card, string type) {
if (type == "Dealt") {
if (hasAuthority) {
card.transform.SetParent(PlayerHandZone.transform, false);
card.GetComponent<PlayableCard>().FlipCard();
} else {
card.transform.SetParent(OpponentHandZone.transform, false);
}
} else if (type == "Played") {
if (!hasAuthority) {
card.transform.SetParent(OpponentDropZone.transform, false);
card.GetComponent<PlayableCard>().FlipCard();
} else {
card.transform.SetParent(PlayerDropZone.transform, false);
}
}
}
The Init()
method just populates the card layout with the scriptable object data like so:
public class PlayableCard : MonoBehaviour {
public GameObject cardFront;
public GameObject cardBack;
public Text nameText;
public Text descriptionText;
public Text costText;
public Text attackText;
public Text healthText;
public Image artworkImage;
public Card card;
public Zone zone = Zone.HAND;
public void Init() {
artworkImage.sprite = card.artwork;
nameText.text = card.name;
descriptionText.text = card.description;
costText.text = card.manaCost.ToString();
attackText.text = card.attack.ToString();
healthText.text = card.health.ToString();
}
public void FlipCard() {
cardFront.SetActive(!cardFront.activeInHierarchy);
cardBack.SetActive(!cardBack.activeInHierarchy);
}
}
My understanding is that the above should generate the card on the server, spawn it, and then replicate the position setting on the clients, data should already be there on the game object in the text fields, but that doesn't seem to be the case. What am I doing wrong?
Comment