41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
|
||
|
|
public class NewBehaviourScript : MonoBehaviour,IPointerClickHandler
|
||
|
|
{
|
||
|
|
public Camera camera;
|
||
|
|
public GameObject target;
|
||
|
|
|
||
|
|
private bool a=false;
|
||
|
|
|
||
|
|
public void OnPointerClick(PointerEventData eventData)
|
||
|
|
{
|
||
|
|
AutoMoveCamera.schedule = 0;
|
||
|
|
camera.GetComponent<AutoMoveCamera>().enabled = false;
|
||
|
|
a = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if (a == true)
|
||
|
|
{
|
||
|
|
// 平滑移动
|
||
|
|
camera.transform.position = Vector3.Lerp(camera.transform.position, target.transform.position, 0.01f );
|
||
|
|
|
||
|
|
// 平滑旋转
|
||
|
|
camera.transform.rotation = Quaternion.Slerp(camera.transform.rotation, target.transform.rotation, 0.03f);
|
||
|
|
|
||
|
|
// 检查是否接近目标位置和旋转
|
||
|
|
if (Vector3.Distance(camera.transform.position, target.transform.position) < 0.1f &&
|
||
|
|
Quaternion.Angle(camera.transform.rotation, target.transform.rotation) < 0.1f)
|
||
|
|
{
|
||
|
|
camera.transform.position = target.transform.position;
|
||
|
|
camera.transform.rotation = target.transform.rotation;
|
||
|
|
a = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|