1
我正在關注Survival Shooter統一教程,並且在教程中向下給出的代碼用於使相機跟隨玩家。代碼正在工作,但是我該如何改變它,以便它在給定的X和Y處停止跟隨玩家點。Unity:停止攝像機跟隨播放器?
代碼
public Transform target; // The position that that camera will be following.
public float smoothing = 5f; // The speed with which the camera will be following.
Vector3 offset; // The initial offset from the target.
void Start()
{
// Calculate the initial offset.
offset = transform.position - target.position;
}
void FixedUpdate()
{
// Create a postion the camera is aiming for based on the offset from the target.
Vector3 targetCamPos = target.position + offset;
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}