본문 바로가기
유니티 엔진

UV scroll script

by 대마왕J 2015. 5. 7.

using UnityEngine;
using System.Collections;

public class NxTextureUVScroll : 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);
    }
 
 }
}

반응형

댓글