I’ve got a Sprite inside a Sprite Renderer and it looks great. However, when I click a button I want that sprite to change from one Sprite to another. However, my second sprite is much larger than the first. As a result, it’s overflowing my Sprite Renderer.
Here is the code attached to my button:
public Sprite[] myCardSprites;
public void changeCardArtwork ()
{
GameObject g = GameObject.FindGameObjectWithTag ("CardArt");
SpriteRenderer s = g.GetComponent<SpriteRenderer> ();
foreach (Sprite currentSprite in myCardSprites)
{
//Set the image to the Rhino
if (currentSprite.name == "Rhino")
{
s.sprite = currentSprite;
}
}
}
I’ve tried a couple of differnt things like changing the transform.localscale on the SpriteRender and tried Sprite.texture.Resize. I also tried to add a Rect Transform onto my SpriteRender to sort of set bounds. Nothing has worked so far.
What I’d love to happen is for the sprite to just take on the size of the sprite renderer.
Thanks in advance.