I’m testing Unity Mirror for a multiplayer card.
I instantiate the card, set it to a random card, then have it spawn. This works as intended for the host, but for the client, the card arrives with its default values, as though the RandomizeCard method was never run.
Any idea how I can pass the card information to the client?
Here’s the Spawn Method being called
GameObject card = Instantiate(card1, new Vector2(0, 0), Quaternion.identity);
Card cardScript = card.GetComponent<Card>();
cardScript.RandomizeCard();
NetworkServer.Spawn(card, connectionToClient);
Here’s the RandomizeCard method that changes the data of the card.
public void RandomizeCard()
{
Sprite _randomImage = cardImages[Random.Range(0, cardImages.Count)];
cardImage.sprite = _randomImage;
cardName = _randomImage.name;
}
I experimented by setting the rotation of the card after instantiation, and then spawning it, and the new rotation went through to the client.
So, it seems the properties inherent to the GameObject went through, but the properties of the attached Card script are not going through.
Miles Cohn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.