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.