90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AutoMoveCamera2 : MonoBehaviour
|
|
{
|
|
public Camera camera;
|
|
public GameObject parentTarget;
|
|
|
|
public List<GameObject> StartShowTargets; // 开始运动时显示的物体
|
|
public List<GameObject> EndHiddenTargets; // jieshu运动时隐藏的物体
|
|
private bool isStart = true;
|
|
|
|
private RootPanelBingSpace component;
|
|
// 接近目标
|
|
//public List<GameObject> targets; // 目标物体
|
|
|
|
public static int schedule=0;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
StartCoroutine(autoMove());
|
|
}
|
|
|
|
private IEnumerator autoMove()
|
|
{
|
|
|
|
while (true)
|
|
{
|
|
if (AutoMoveCamera.runState==2)
|
|
{
|
|
if (isStart)
|
|
{
|
|
StartShowTargets?.ForEach(target => target.SetActive(true));
|
|
isStart = false;
|
|
}
|
|
|
|
if (component != null)
|
|
{
|
|
component.HiddenPanel();
|
|
}
|
|
|
|
// 目标位置
|
|
Transform child = parentTarget.transform.GetChild(schedule);
|
|
Vector3 targetPosition = child.position;
|
|
|
|
// 计算每帧的匀速移动
|
|
float speed = 5f; // 设定你希望摄像机的匀速速度(单位:每秒的移动距离)
|
|
camera.transform.position = Vector3.MoveTowards(camera.transform.position, targetPosition, speed * Time.deltaTime);
|
|
|
|
float rotationSpeed = 60f; // 旋转速度
|
|
camera.transform.rotation = Quaternion.RotateTowards(camera.transform.rotation, child.rotation, rotationSpeed * Time.deltaTime);
|
|
|
|
// 检查是否接近目标位置和旋转
|
|
if (Vector3.Distance(camera.transform.position, child.position) < 0.1f &&
|
|
Quaternion.Angle(camera.transform.rotation, child.rotation) < 0.1f)
|
|
{
|
|
camera.transform.position = child.position;
|
|
camera.transform.rotation = child.rotation;
|
|
|
|
component = child.gameObject.GetComponent<RootPanelBingSpace>();
|
|
if (component != null)
|
|
{
|
|
component.ViewPanel();
|
|
}
|
|
|
|
schedule++;
|
|
if (schedule==parentTarget.transform.childCount)
|
|
{
|
|
schedule = 0;
|
|
AutoMoveCamera.runState = 1;
|
|
isStart = true;
|
|
EndHiddenTargets?.ForEach(target => target.SetActive(false));
|
|
}
|
|
yield return new WaitForSeconds(6f);
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
|
|
}
|
|
}
|