//SubCameraの設定
//SubCanvasの設定(Canvasをコピー)
// GameObjectにアタッチ
using UnityEngine;
using UnityEngine.UIElements;
public class Camera : MonoBehaviour
{
private GameObject mainCamera; //メインカメラ格納用
private GameObject subCamera; //サブカメラ格納用
[SerializeField] GameObject target; //Playerに設定
private Vector3 offset;
void Start()
{
mainCamera = GameObject.Find("MainCamera");
subCamera = GameObject.Find("SubCamera");
subCamera.SetActive(false);
}
void Update()
{
Vector3 playerPos = this.target.transform.position;
if (playerPos.x >= mainCamera.transform.position.x + 8f)
{
//サブカメラをアクティブに設定
mainCamera.SetActive(false);
subCamera.SetActive(true);
}
else if(playerPos.x >= mainCamera.transform.position.x - 10f)
{
//メインカメラをアクティブに設定
subCamera.SetActive(false);
mainCamera.SetActive(true);
}
}
}