Hello guys, how can I swtich between using cinemachine cameras?
I've got a script set up to switch between three different Cinemachine cameras, currently it works in handling switches between my character camera and my building camera. I've added a third camera but for some reason the script is not changing the priority of the cameras when using the function for the third camera. It produces the debug logs set in the function so it is reaching the lines of code that should change the priority but yet the priority does not change. Also no errors are being produced in the console. All cameras are set up on the script in the inspector. Could anyone help me figure out as to why this is happening?
Please see code below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CameraManager : MonoBehaviour
{
public GameObject characterCamera;
public GameObject buildingCamera;
public GameObject observationCamera;
public enum CameraType
{
CharacterCamera,
BuildingCamera,
ObservationCamera
}
public CameraType currentCamera;
void Start()
{
currentCamera = CameraType.CharacterCamera;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.V))
{
if (currentCamera == CameraType.CharacterCamera)
{
Debug.Log("V key has been pressed.");
EnableObservationCamera();
}
if (currentCamera == CameraType.ObservationCamera)
{
Debug.Log("V key has been pressed.");
EnableCharacterCamera();
}
}
}
public void EnableCharacterCamera()
{
if (currentCamera != CameraType.CharacterCamera)
{
observationCamera.GetComponent<CinemachineVirtualCamera>().Priority = 1;
buildingCamera.GetComponent<CinemachineFreeLook>().Priority = 1;
characterCamera.GetComponent<CinemachineFreeLook>().Priority = 10;
currentCamera = CameraType.CharacterCamera;
}
}
public void EnableBuildingCamera()
{
if (currentCamera != CameraType.BuildingCamera)
{
characterCamera.GetComponent<CinemachineFreeLook>().Priority = 1;
observationCamera.GetComponent<CinemachineVirtualCamera>().Priority = 1;
buildingCamera.GetComponent<CinemachineFreeLook>().Priority = 10;
currentCamera = CameraType.BuildingCamera;
}
}
void EnableObservationCamera()
{
Debug.Log("Observation camera function has been entered");
if (currentCamera != CameraType.ObservationCamera)
{
characterCamera.GetComponent<CinemachineFreeLook>().Priority = 1;
buildingCamera.GetComponent<CinemachineFreeLook>().Priority = 1;
observationCamera.GetComponent<CinemachineVirtualCamera>().Priority = 10;
currentCamera = CameraType.ObservationCamera;
Debug.Log("Camera has switched");
}
}
}
Your answer
Follow this Question
Related Questions
How can I get all cameras enabled true false states ? 0 Answers
How can i wait StartCoroutine to be finished in one script before starting a second script ? 1 Answer
How can I get the game object that a particle trigger detects? 0 Answers
How do i make the player to be "Idle" when reaching the mouse position ? 1 Answer