unity材質球貼圖滾動


   using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {

    //滾動速度
    public float HorSpeed = 1.0f;
    public float VerSpeed = 1.0f;

    //Offset偏移量
    //水平滾動Offset.y
    public float HorMin = 1.0f;
    public float HorMax = 2.0f;
    //垂直滾動Offset.x
    public float VerMin = 1.0f;
    public float VerMax = 2.0f;

    //渲染器
    MeshRenderer MeshR ;

    private void Awake()
    {
        //獲得渲染器
        MeshR = GetComponent<MeshRenderer>();
    }

    private void Update()
    {

        Vector2 Offset = new Vector2(
            (MeshR.material.mainTextureOffset.x > HorMax) ? HorMin : MeshR.material.mainTextureOffset.x + Time.deltaTime * HorSpeed,
           (MeshR.material.mainTextureOffset.y > VerMax) ? VerMin : MeshR.material.mainTextureOffset.y + Time.deltaTime * VerSpeed
           );

        MeshR.material.mainTextureOffset = Offset;
    }

}
 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM