I have an array with about 25 sprites. I also have a string that will hold a sprite name, how would I be able the Array.IndexOf() to find the index of a sprite. Here is my crude implementation, but I keep getting an error:
//Decleration of Background Images
[Header("Background Images")]
public Sprite[] spriteBackgroundList;
[Header("Sprite Renderer")]
[SerializeField]
private SpriteRenderer backgroundRenderer;
[Header("Variables")]
public string currentBackground;
//Start is called before the first frame update
private void Start()
{
currentBackground = "Black Background";
}
//Update is called once per frame
private void Update()
{
if(currentBackground!.Contains(backgroundRenderer.sprite.name))
{
backgroundRenderer.sprite = spriteBackgroundList[Array.IndexOf(spriteBackgroundList, s => s.name == currentBackground)];
}
}