Hi,
I am working on some kind of card game. Each card has 3 images on it. (front, back and hidden). So for each card I created a sprite sheet containing all 3 sides. GameObject wise I created a SpriteRenderer and attached a script to it. It contains an array of sprites which will hold the different possible cards and an integer where to set which card we currently have and another one which side of the card is shown.
The code looks like this:
public class CardGame : MonoBehaviour {
public Sprite[ ] allSprites =newSprite[10]; // 10 different cards
public int cardNumber =0; // which card this is
public int shownface =0; // Which side of the card should be shown
// Use this for initialization
void Start () {
SetSprite();
}
void SetSprite()
{
SpriteRenderer sr = GetComponent();
sr.sprite = allSprites[cardNumber];
}
…
So in the editor I attached my 10 different sprites so they fill the Sprite[ ] Array - no problem here.
Then I set the cardnumber and on screen I see the card perfectly all shown with the first image of the single sprite which in this case is the front side.
Now I want to select the second image of the multiple sprite via script without creation an animation or a state so I can handle all cards the same way.
Is there a simple way to select a different part of the texture like:
sr.sprite = sr.sprite[2];
or similar? Or is the only way to change the image to create an animation?
I am a bit lost here.
Any ideas?
Thx.