Matching Card Game - decorating cards issue

Hello. I’m working on a little matching game (C#) where the player have to match two cards.
There are 8 cards on the desk and the player has to find two matching ones.

I have made one prefab called “card” - the card gets the texture (front and back) from a scriptable object. I have four scriptable objects called Star, Apple, Heart and Banana.

So far I have managed to place 8 cards on the screen all with the “back texture” showing - and when clicked, it shows the front side (either star, apple, heart or banana).

But I have issues decorating the cards - I know I have to select two cards, then inject it with one of the scriptable objects; and then head on to the next two - decorate them and so on.

But I just cant figure out how to do so…

Am I overcomplicating a simple game by this approach? Would it be better to make a prefab for card (star, apple, banana, heart) and then just load two of each card into the gamescene?

Any input appreciated!

In general, I’d say yes you are definitely over complicating it :wink: Using multiple prefabs would work just fine. In fact, you can even make one prefab and then several prefab variants based off of it, each with their own image.

On the other hand if you are specifically trying to learn a technique like how to dynamically apply textures to an object then you’ll have to give us a little more to help you work off of. What part are you struggling with specifically?

Why don’t you just ‘inject’ the scriptableObject data at the start? Then when the card is ‘flipped’, you show the cached texture you gave it from the beginning.

I wouldn’t use scriptable objects, you can just change the sprites on the game objects

myrend.sprite = Resources.Load<Sprite>("Things/" + mything.Spritename);

Use an Array to hold card data, assign them all their values (2 of each) and “shuffle” them into random positions. When the player selects a card, you look up the card type in the array, then change the sprite to display it.