unity无缝拼接背景移动(修改shader值实现)

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));
    }

}