|
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]
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|