This is a very common small function. For example, when we are playing a horizontal version of the game, the background animation will move at a certain frequency, and there are many ways to realize it.
For example, use UGUI's image+animtion animation method to realize k-frame by yourself.
It can also be realized by using the function of the shader itself. The key functions are as follows:
public Material material;
public float _offset;
private int paraId;
void Start()
{
material = GetComponent<Image>().material;
paraId = Shader.PropertyToID("factor");
}
// Update is called once per frame
void Update()
{
material.SetTextureOffset("_MainTex", new Vector2(_offset, 0));
}
The matching material ball is as follows: