第一步:创建一个Quad,然后把bg这张背景图片拖上去,然后呢,就会自然形成一个材质球,哇哦,好快~~~然后把下面这个脚本挂上去就可以啦。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class bgmove : MonoBehaviour
{
private Material material;
private float speed = 0.2f;
float y;
void Start()
{
StartCoroutine(Example());
material = transform.GetComponent<MeshRenderer>().material;
}
public void change()
{
if (y <= -1)
{
y = 1;
}
}
public void move()
{
y = y - 0.05f;
material.mainTextureOffset = new Vector2(0, y);
}
IEnumerator Example()
{
print(Time.time);
yield return new WaitForSeconds(0.01f);
print(Time.time);
}
private void FixedUpdate()
{
Example();
move();
change();
//material.mainTextureOffset += new Vector2(0, Time.deltaTime * speed);
}
}