Hey,
I created a prefab called “CardPrefab” and attached a SpriteRenderer and this script to it:
public class Card : MonoBehaviour
{
public SpriteRenderer spriteRenderer;
public Sprite cardSprite;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
cardSprite = LoadSomeSprite();
spriteRenderer.sprite = cardSprite;
}
}
Also I have the following script to instantiate prefabs:
/*Init Card prefabs*/
public class InitCards : MonoBehaviour
{
public GameObject cardPrefab;
void Start()
{
Sprite cardSprite = LoadOtherSprite();
GameObject cardClone = Instantiate(cardPrefab, new Vector3(0, 0, 0), Quaternion.identity);
cardClone.GetComponent<Card>().cardSprite = cardSprite;
}
}
I want to update the instantiated prefab with annothe sprite, but it doesn’t work. Unity renders twice the same sprite. How can I fix that ?
Thanks in advance.