WORLD - Shuffling Cards and Changing Materials On Self

I’m attempting to recreate an old world of mine from before VRC updated to Unity 2018. In that world I had a deck of tarot cards that, upon pressing a button, would all spawn in the same place on the table then fan out and, thanks to some rigidbody settings, freeze in place to form a deck on a table. It essentially acted like its own shuffling system. This time around, I want to make sure the deck is shuffling properly. Here’s my needs for this process:

  • Pressing a button will spawn/despawn the deck.
  • Pressing a different button will shuffle the deck.
  • Cards must be grabbable/moveable.
  • Entire deck should be accessible to the player while deck is active. (I saw an example of a card game in udon# but the deck was placed out of bounds, and a card was pulled in bounds when a player pressed a button. I want the user to be able to select a card from any part of the deck, rather than receiving one card at a time.)

I’m also trying to figure out how to make the material on a button change so I can turn the button green when the target gameobject is active, then turn red when the gameobject is inactive. pretty simple, but i am not good at all with programming. math was my worst subject in school and programming is just formulas with words instead of numbers, which means i have an even worse time understanding Udon lmao. i apologize if these are stupid questions that have already been answered, i tried looking for solutions and found some similar situations but I have no idea how to take those Udon graphs and change them to suit my needs.

Thanks in advance!

So, I could probably write this if I had the time, but I don’t. Plus it’ll be a fun project for yourself to figure out and learn.

So, first off, you’ll want to use udon# for this.

It’ll make your life a lot easier and keeps the logic simple.

Secondly, you’ll only really need 2 scripts.
The Game Controller and the Card Controller.
Lets call them GC and CC for short.

The GC will be responsible for the state of the game itself, it’ll have 3 arrays and at least one intiger.
Array 1 will store all possible cards you want your game to have, Array 2 will contain all cards (all cards will have their own CC) and Array 3 will be the same size as Array 1 but empty.

Whenever the cards are shuffled, the GC will copy all possible cards to Array 3. Then we’ll use math.random to pick a random card and copy it’s settings to Array 2 (the actual cards) we’ll keep picking a random card and copying it to Array 2 until we’ve filled all cards.

If you want to prevent duplicate cards, you can also remove the data in array 3 when you’ve copies it, and do a check if the random choice you made contains a valid card or not.

The CC on the other side will get it’s data from the GC. it’s sole job is to synchronize it’s own state properly with the players. for this UdonSynced can be used. Additionally it’ll be responsible of showing the correct texture/material, this could be done with a simple integer to tell the card what card it should display.

If you want to see this kind of system in action,
you can check out my world on vrc, it’s called “know your friends in space” and I’m using a similar system to put random questions on the board