1.先把无缝拼接图设置成如下:
unity无缝拼接背景移动(修改shader值实现)
2.新建一个材质球
unity无缝拼接背景移动(修改shader值实现)
3.c#代码修改Shader里的值
unity无缝拼接背景移动(修改shader值实现)

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

public class BackGround : MonoBehaviour {
    /// <summary>
    /// 背景图移动速度
    /// </summary>
    float speed;
    /// <summary>
    /// 背景材质球
    /// </summary>
    Material material;
    float y;
    public float Y
    {
        get { return y; }
        set { y = value; }
    }
    void Start () {
        material = GetComponent<Image>().material;
        speed = 0.1f;
    }

    void Update()
    {
        Y += Time.deltaTime * speed;
        //给shader里对应的字段赋值
        material.SetTextureOffset("_MainTex",new Vector2 (0,Y));
    }

}

相关文章:

  • 2021-07-28
  • 2021-04-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-01-01
猜你喜欢
  • 2021-11-30
  • 2021-11-26
  • 2022-01-01
  • 2021-12-09
  • 2022-01-01
相关资源
相似解决方案