I have several different backgrounds I want to use, but I don’t know how to make the sprite render change to a random one of my backgrounds. I was thinking of using an array and putting my backgrounds in it and the choosing a random one at start, but I have no idea how to do it. Any help would be appreciated.
Try this,
using UnityEngine;
using System.Collections;
public class RandomBackground : MonoBehaviour {
public SpriteRenderer backgroundSpriteRenderer;
public Sprite[] backgroundSprites;
// Use this for initialization
void Start () {
backgroundSpriteRenderer.sprite = backgroundSprites [Random.Range (0, backgroundSprites.Length)];
}
}
Make sure you assign the spriteRenderer, and background sprites in the inspector.