/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.Demo { using Opsive.UltimateCharacterController.Character; using Opsive.UltimateCharacterController.Game; using Opsive.UltimateCharacterController.Utility; using UnityEngine; /// /// Switch the camera to a first or third person perspective. /// public class PerspectiveSwitchZone : MonoBehaviour { [Tooltip("Should the camera switch to a first person perspective?")] [SerializeField] protected bool m_FirstPersonPerspective; /// /// An object has entered the trigger. /// /// The object that entered the trigger. private void OnTriggerEnter(Collider other) { if (!MathUtility.InLayerMask(other.gameObject.layer, 1 << LayerManager.Character)) { return; } var characterLocomotion = other.GetComponentInParent(); if (characterLocomotion == null) { return; } var cameraController = UnityEngineUtility.FindCamera(characterLocomotion.gameObject).GetComponent(); cameraController.SetPerspective(m_FirstPersonPerspective); } } }