相机跟随 Rigidbody2D 每隔几秒抖动一次背景(非刚体)对象(障碍物)。Profiler 中的 FPS 很好,接近 100。插值也很好。使用Unity 2017.4.12(LTS)
GIF GIF 视频在这里
相机跟随脚本
public class CameraFollow : MonoBehaviour {
public float followRange = 0.5f;
public float cameraZ;
public Transform Player;
public Vector3 newPos;
void Start () {
cameraZ = transform.position.z;
}
void FixedUpdate() {
newPos = new Vector3(Player.position.x + followRange, 0, cameraZ);
transform.position = Vector3.Lerp(transform.position, newPos, 0.5f);
}
}
Run Code Online (Sandbox Code Playgroud)
播放器脚本:
public class PlayerBall : MonoBehaviour {
public float xSpeed = 10;
// Update is called once per frame
void FixedUpdate () …Run Code Online (Sandbox Code Playgroud)