What I want to do is I have 2 image slot which will show playing cards cover on default , when player pressed a button, both slots will randomly changed into a new card.
I know some stupid way of doing this …that I add all playing cards in advance to these two slots(which will create dozens of canvas), and then I check the variable and enable the one canvas representing be card.but I seriously doubt there will be better way.
To change the image on button is really easy
create variable that stores the image or a list. when you select what card to play or what image you want to play then use a code like this. sorry if the capitals are not correct.
this.gameObject.GetComponent().sprite = WhatEverTheNewImageIs;
Or you can try these. Take an array of sprites and then select any random sprite from that array
public Sprite[] allSprites;
public void ButtonClicked()
{
//these is for UI
getComponent<Image>().sprite = allSprites[Random.range(0, allSprites.length);
//if your working on gameObject then use getComponent<SpriteRenderer>().sprite = allSprites[Random.range(0, allSprites.length);
}