Error CS0201 when trying to render random sprite

Hi,

I am trying to write a really simple script which is supposed to render a random sprite. The first part of the code was working, I was able to assign different sprites through the inspector. Than came the hard part for me. No matter how I try, it always gives me Error CS0201. I know I probably doing some basic stuff wrong here but as a rookie I can’t figure out what. Please help me :slight_smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomDice : MonoBehaviour {
	
	[System.Serializable]
	public class SpriteList
	{
		public Sprite[] sprites;
	}
	public Sprite[] SpriteLists;
	void Start ()
	{
		SpriteRenderer sr = GameObject.GetComponent<SpriteRenderer>();
		sr.sprite = SpriteList[Random.Range(0, 5)];
	}
}

You’re trying to declare a variable within the constructor.

     public class SpriteList
     {
         public Sprite[] sprites;
     }

Try taking out:

         public Sprite[] sprites;

It doesn’t seem to work. However I noticed that after a restart it throws new errors:

Assets/RandomDice.cs(16,15): error CS0118: RandomDice.DiceList' is a type’ but a variable' was expected Assets/RandomDice.cs(16,15): error CS0119: Expression denotes a type’, where a variable', value’ or `method group’ was expected