找回密码
 立即注册
楼主: 小米

[渲染] Unity3D UV动画代码效果 附图

[复制链接]
发表于 2012-11-20 12:21 | 显示全部楼层 |阅读模式

js版:
[code=javascript]var scrollSpeed = 5;
var countX : int = 4;
var countY : int = 4;


private var offsetX = 0.0;
private var offsetY = 0.0;
private var singleTexSize;


function Start() {
    singleTexSize = Vector2(1.0/countX, 1.0/countY);
    renderer.material.mainTextureScale = singleTexSize;
}
function Update ()
{
   
    var frame = Mathf.Floor(Time.time*scrollSpeed);
    offsetX = frame/countX;
    offsetY = -(frame - frame%countX) /countY / countX;
    renderer.material.SetTextureOffset ("_MainTex", Vector2(offsetX, offsetY));
}[/code]
C#版:
[code=csharp]using UnityEngine;
using System.Collections;
using System;


public class OffsetTexs : MonoBehaviour
{
    public int scrollSpeed=5;
    public int countX=4;
    public int countY=4;


    private float offsetX=0.0f;
    private float offsetY=0.0f;
    private Vector2 singleTexSize;


// Use this for initialization
void Start () {
        singleTexSize=new Vector2(1.0f/countX,1.0f/countY);
        renderer.material.mainTextureScale=singleTexSize;
}
// Update is called once per frame
void Update () {
        float frame=Mathf.Floor(Time.time*scrollSpeed);
        offsetX=frame/countX;
        offsetY=-(frame-frame%countX)/countY/countX;
        renderer.material.SetTextureOffset("_MainTex",new Vector2(offsetX,offsetY));
}
}[/code]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2012-11-21 16:47 | 显示全部楼层
喜欢这个效果  下来试试看{:5_427:}
发表于 2012-11-23 10:28 | 显示全部楼层
谢谢分享,感谢。。。。{:5_427:}
发表于 2012-12-3 09:58 | 显示全部楼层
看一下。。。。。。。
发表于 2012-12-8 15:23 | 显示全部楼层
学习学习 谢谢分享
发表于 2012-12-13 20:35 | 显示全部楼层
谢谢楼主!!!!!!!!!!!!!!
发表于 2013-4-22 15:08 | 显示全部楼层
换成shader 应该怎么写呢?
发表于 2013-4-27 09:42 | 显示全部楼层
学习 学习 {:5_387:}学习中呀~
发表于 2017-2-20 14:05 | 显示全部楼层
很不错
发表于 2017-2-20 14:20 | 显示全部楼层
楼主是超人
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 02:55 , Processed in 0.094235 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表