I'm currently working on the "Extending Space Shooter" video tutorial, in the section where it is explained how to create a scrolling background.
Instead of using the technique detailed in the video, I've written my code (see below) such that it changes the offset of the background texture/material on the quad, and I'm wondering which of the two approaches is the more efficient in terms of resource use.
// BGScroller.cs
using UnityEngine;
using System.Collections;
public class BGScroller : MonoBehaviour
{
public float scrollSpeed;
private Material bgMaterial;
private float offsetSpeed;
void Start ()
{
Renderer bgRenderer = GetComponent< Renderer > ();
bgMaterial = bgRenderer.material;
offsetSpeed = scrollSpeed / transform.localScale.y;
}
void Update ()
{
float newOffset = Mathf.Repeat (Time.time * offsetSpeed, 1);
bgMaterial.SetTextureOffset ("_MainTex", new Vector2 (0, newOffset));
}
}