Hello! I have two quick questions, I am trying to leverage the ActivateCameraWithDistance.cs script. I attach the script to a GameObject in my scene and tell it to look out for the player. I then create a new virtual camera which I use as the new camera.
However I get the following error message twice. The code works in that once the player enters the space the camera swaps, but once he leaves the space the camera does not revert back.
NullReferenceException: Object reference not set to an instance of an object
Cinemachine.Examples.ActivateCameraWithDistance.SwitchCam (Cinemachine.CinemachineVirtualCameraBase vcam) (at Assets/CinemachineExamples/Share
Q2. I thought I would try and repurpose the above script a little so once the player hits the X key, the camera would default back to the player camera and the new virtual camera would then be disabled. This was my code:
public void SwitchCam(CinemachineVirtualCameraBase vcam)
{
if (Camera.main.GetComponent<CinemachineBrain>().ActiveVirtualCamera.Name != vcam.Name)
{
vcam.MoveToTopOfPrioritySubqueue();
// This is the part I have tried to add to disable the camera once X is pressed. But it changed nothing.
if(Input.GetKeyDown(KeyCode.X)){
vcam.enabled = false;
initialActiveCam.MoveToTopOfPrioritySubqueue();
}
}
}
Thanks everyone.