- Home /
Sprite.Create makes invisible sprites, even when nothing is changed.
In my game, I want my player to display one of two sprites.
//spr is a public Sprite variable
if (hasAltCostume) {
//this code will be replaced by something more complicated later
GetComponent<SpriteRenderer> ().sprite = Sprite.Create (spr.texture, spr.rect, spr.pivot);
} else {
GetComponent<SpriteRenderer> ().sprite = spr;
}
When hasAltCostume is false, the code works fine. When it's true, the player is invisible.
What's going on? Shouldn't Sprite.Create(spr.texture, spr.rect, spr.pivot) just be a clone of spr?
Comment
Can you screenshot the Sprite Renderer's inspector after this block runs?
Best Answer
Answer by snuffysam · May 09, 2017 at 05:56 AM
Never mind, I figured it out- sprite.textureRect is the rect that should be used, not sprite.rect. Similarly for sprite.pivot.
Your answer
Follow this Question
Related Questions
Sprite moving as a flag 1 Answer
Translucent sprites appear solid 0 Answers
Is there any way for a Sprite Renderer to use mipmaps? 1 Answer