I am making a card-based game similar to Triple Triad. The game is played in top-down 2D over a 3x3 grid where players place their cards onto one of the open grid positions. Therefore I need to make a card which is 2D, holding a picture on its face and a different picture on its back so that when animating a card to flip it would look like an actual card.
The game will have about 30 cards with different pictures and other things (each card has 4 values in the north, east, south and west positions on the face of the card).
How would I go about making these cards to use in my game? I have read something about prefabs but just asking in case there is another option or perhaps a better example for my case?
Create a single card prefab. The prefab would be composed of a background with a blank front, a plane to display the face of the card on and a script. The script would contain some public variables or methods to set the value for the face of the card. In the script there would be an array of textures something like:
public Texture artex; // C#
var artex : Texture; // Unityscript
All your face textures for all your cards would go into this array. Then at runtime, you would Instantiate() the deck of 30 cards (or only the 9 you need) and assign them values. The card would then set the texture for the face of the card according to the value you assigned to the card. Something like:
renderer.material.mainTexture = artex*;*
If your target platform is mobile, I’d test performance of this (or any) solution early. If it is too slow, you can use a texture atlas instead of individual textures for the face of the cards. Add-on packages like EZGUI and I assume NGUI make this fairly easy.