11
27

 

 

대마왕님 블로그 참고.

 

using UnityEngine;
using System.Collections;
public class UVscroll : MonoBehaviour 
{
    private Vector2 texcoord = Vector2.zero;
	public int materialIndex = 0;
	public string textureName = "_MainTex";
	public Vector2 UVaniRate = new Vector2(1.0f,1.0f);
	private Vector2 TexUVScale;

	void Start()
    {
        TexUVScale = GetComponent<Renderer> ().material.GetTextureScale(textureName);
    }

	// Update is called once per frame
    void LateUpdate () 
    {
        texcoord += UVaniRate * Time.deltaTime;
        // for prevent Huge UV number
        texcoord.x = texcoord.x % 1.0f;
        texcoord.y = texcoord.y % 1.0f;
        if (GetComponent<Renderer>().enabled ) 
        {
            GetComponent<Renderer>().materials[materialIndex].SetTextureOffset (textureName,texcoord);
        }
    }
}

 

COMMENT