A simple script for animating the texture of an object. This example scrolls the texture up like movie credits. Add it to a GameObject
that has a textured material.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScrollingTexture : MonoBehaviour {
public float ScrollSpeed = 0.01f;
private Vector2 offset = new Vector2(0f,0f);
private Renderer matRenderer;
// Use this for initialization
void Start () {
matRenderer = GetComponent<Renderer>();
}
// Update is called once per frame
void Update () {
offset.y -= Time.deltaTime * ScrollSpeed;
matRenderer.material.SetTextureOffset("_MainTex", offset);
}
}