0
\$\begingroup\$

I want to assign cards to different players in the room. I've a Class "Cards" that contains an array of 52 cards like this: "2_of_spades","3_of_spades"....... and so on. All i want is to assign random indexes or values to different players on the basis of which I'll instantiate Cards Sprites. How can I do that? I've heard that there are RPC calls but how do I manage to make a "Middle Man" script that would deal with different players?

\$\endgroup\$
1
\$\begingroup\$

Make a CmdPullCard command for the host, send the command from the player, check if the card has been already pulled before, if not send the card string to the player. (If you're unsure on how to do this, read up on your Unity Networking).

So, something like this:

var num = -1;
string card = "";
[Command]
CmdPullCard(){
    While(card!=""){ //check if the card you pulled is empty or not
    num = rnd.Next(0,53);
    card = cards[num]; //pull a card from the deck
    }
cards[num]=""; //set the card as empty so it can't be pulled again
}

Of course this code is unoptimized and might run too many times before it gives a card, especially if the number of cards are low, since this is a random number. To avoid this, you need to actually remove the element of the array and change the random number generators max number amount but that'll take more coding.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer but this one is I guess Unity Networking based but I was looking for Photon. \$\endgroup\$ – Faizan Khan Feb 2 '17 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.