材质渐变出现及UV移动

using UnityEngine;
using System.Collections;

public class ScrollBehaviour : MonoBehaviour
{

public int materialIndex;
public string textureName = "_MainTex";
public Vector2 uvAnimationRate = new Vector2(1f, 0f);
private Vector2 uvOffset = Vector2.zero;

private Material mat;
private Color col;
private float colorAhpha=0;
private void Start()
{
col = new Color(0.54f,0.45f,0.25f, colorAhpha);
mat = gameObject.transform.GetComponent<Renderer>().material;

}


private void LateUpdate()
{
if (colorAhpha <= 0.45f)
{
colorAhpha = colorAhpha + 0.001f;
col.a = colorAhpha;
mat.SetColor("_TintColor", col);
}
uvOffset += (Vector2)(uvAnimationRate * Time.deltaTime);
if (base.GetComponent<Renderer>().enabled)
{
base.GetComponent<Renderer>().materials[materialIndex].SetTextureOffset(textureName, uvOffset);
}
}
}

 

posted @ 2017-11-29 18:04  joson_zeng  阅读(333)  评论(0编辑  收藏  举报