Hey guys,
I’m wondering if it’s possible to implement a 2D Background Generator where the background image is randomly selected from an array. I could have just created a long texture for the background, but I want the background to be different each time the game is played. This is the script I have so far:
using UnityEngine;
using System.Collections;
public class BackgroundGenerator : MonoBehaviour
{
public float scrollSpeed = 0.5f;
private Vector2 savedOffset;
//Use this for initialization
void Start ()
{
savedOffset = renderer.sharedMaterial.GetTextureOffset ("_MainTex");
}
//Update is called once per frame
void Update ()
{
#region Scrolling Texture
float y = Mathf.Repeat (Time.time * scrollSpeed, 1);
Vector2 offset = new Vector2 (savedOffset.x, y);
renderer.sharedMaterial.SetTextureOffset ("_MainTex", offset);
#endregion
}
}