我正在尝试开发一个 2D Plattformer,我不希望 y.axis 相机在跳跃时跟随。我的公共布尔称为“isJumping”。
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothing = 5.0f;
public float yOffset = 0.0f;
private Vector3 offset;
private void Start()
{
offset = transform.position - target.position;
}
private void FixedUpdate()
{
Vector3 targetCamPos = target.position + offset;
targetCamPos.y += yOffset;
transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}