using Cinemachine; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Virtual_CameraManager : MonoBehaviour { public static Virtual_CameraManager Instance; public List Cameralist = new List(); public List Canvaslist = new List(); // Start is called before the first frame update void Start() { Instance = this; // 确保只有第一个虚拟摄像机被启用,其他摄像机禁用 for (int i = 0; i < Cameralist.Count; i++) { Cameralist[i].Priority = (i == 0) ? 10 : 0; } HideCanvas(); } // Update is called once per frame void Update() { } public void SwitchToCamera(int cameraIndex) { // 将所有摄像机优先级降低 for (int i = 0; i < Cameralist.Count; i++) { Cameralist[i].Priority = 0; } // 提升选中摄像机的优先级 Cameralist[cameraIndex].Priority = 10; HideCanvas(); Canvaslist[cameraIndex].gameObject.SetActive(true); Debug.Log($"切换到摄像机 {cameraIndex + 1}"); } void HideCanvas() { for (int i = 0; i < Canvaslist.Count; i++) { Canvaslist[i].gameObject.SetActive(false); } } }