unity3d texture2d动画(纹理动画)

using UnityEngine;

using System.Collections;

 

public class classAnimateTiledTexture :MonoBehaviour

{

    public int columns = 5;

    public int rows = 3;

 

    void Start()

    {

        StartCoroutine(updateTiling());

 

        //set thetile size of the texture (in UV units), based on the rows and columns

        Vector2 size = new Vector2(1f/ columns, 1f / rows);

        renderer.sharedMaterial.SetTextureScale("_MainTex", size);

    }

 

    private IEnumerator updateTiling()

    {

        while(true)

        {

            for(int i = rows-1; i >-1; i--)

            {

                for(int j = 0; j<columns; j++)

                {

                    Vector2 offset = new Vector2((float)j / columns,(float)i / rows);

                    renderer.sharedMaterial.SetTextureOffset("_MainTex",offset);

                    yield return new WaitForSeconds(1f);

                }

            }

        }

    }

}

把图片和脚本拖拽到目标对象,设置rows为3,columns为5
目标物体需要加上 Mesh Renderer
把存放图片的Materials给Mesh Renderer的Materials就可以了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值