- Home /
My sprite doesn't render on scene view and game view
I'm trying to make a code to generate a random sprite to put on a face id (Papers please style) when I press R, but it doesn't appear on scene view and the game view when the game is running. If it's not running, the sprite appears normally. And it's not the layer because I checked. Here's the code I wrote:
public class Paper : MonoBehaviour
{
public Sprite[] suits;
public SpriteRenderer suitRenderer;
public Sprite suit;
private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
generatePaper();
}
suitRenderer.sprite = suit;
}
public void generatePaper()
{
suit = suits[Random.Range(0, suits.Length)];
}
}
An image of what's happening.
Answer by Tondoy · Apr 05 at 05:02 AM
Hi, I copied your code and it worked. Only if you don´t set the start suit, no sprite will be rendered at the start. But after the first time I generated a suit there where no cases, in which it didn´t show up. So the problem needs to be some were else. To determine what the problem is I would need more information.
I discovered, i forgot to metion but I did the same system but to the color of the sprite, i exclueded that system and it worked. Thanks.
Answer by Hawaii_Dev · Apr 05 at 11:05 AM
Remember to asign a sprite at the beginning for the sprite to be shown at the start. After that make sure that your suits array has more than 0 sprites in it. And that you also press R on your keyboards.