_xiaofang/xiaofang/Assets/Script/hylScripts/CameraSmoothMove.cs

30 lines
801 B
C#
Raw Normal View History

2024-12-18 11:17:37 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSmoothMove : MonoBehaviour
{
public Transform startPoint; // <20><>ʼ<EFBFBD><CABC>
public Transform endPoint; // <20>յ<EFBFBD>
public float duration = 5f; // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
private float elapsedTime = 0f; // <20><>¼<EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ȥ<EFBFBD><C8A5>ʱ<EFBFBD><CAB1>
void Update()
{
// ȷ<><C8B7><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
if (startPoint != null && endPoint != null)
{
// <20><><EFBFBD>¾<EFBFBD><C2BE><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
elapsedTime += Time.deltaTime;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㵱ǰλ<C7B0><CEBB>
float t = Mathf.Clamp01(elapsedTime / duration);
// ʹ<><CAB9> Lerp ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
transform.position = Vector3.Lerp(startPoint.position, endPoint.position, t);
}
}
}