背景滚动其实就是滚动模型的纹理Offset而已,修改Renderer组件下的Material的贴图的偏移即可。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Texturescorll : MonoBehaviour {
public float speed = .5f;
Renderer renderer;
float offset;
void Start()
{
renderer = GetComponent<Renderer>();
}
void Update()
{
// Increase offset based on time
offset += Time.deltaTime * speed;
// Keep offset between 0 and 1
if (offset > 1)
offset -= 1;
// Apply the offset to the material
renderer.material.mainTextureOffset = new Vector2(0, offset);
}
}
放在3d视角里就是3d视角的滚动