Switching between cameras by C# with animation.

Can I make switching between 2 cameras with basic animation like floating using C#?

Good day @Dagter !

I never had to use it, but i think you need to make a script in a GameObject that is not a camera to controll the cameras. Disable the camera 1 and enable camera 2,

You will find the solution explained in this other post

If helped, markas good answer please :smiley:

BYE !

hello , controlling cameras from a script is an obsolete technique since Unity released Cinemachine

if you are desperately bounded to change camera view from script, i suggest creating 2 empty game objects for positions and Lerp camera transform from one to other.
but i highly recommend using Cinemachine.
there are a lot of tutorials about cinemachine already . give a shoot. if you need further help just ask it.

also if this answer helps please consider upvoting and accepting as correct answer. this way anyone else who searches same question can easily find this.

Hi. You better make them change without animation. Everything you need to do is to enable and disable camera. You put 2 cameras in scene and deactivate one. in script you say something like this

public Camera cam1;
public Camera.cam2;
void Start() 
{
cam1.enabled = true;
cam2.enabled = false;//or Setactive i forgot that 
}
void Update() {
if(Input.GetKeyDown(KeyCode.V))
{
cam2.enabled = true;//or cam2.SetActive(true); 
cam1.enabled = false;//or cam1.SetActive(false); i forgot
}
if(Input.GetKeyUp(KeyCode.V))
{
cam1.enabled = true;//or cam2.SetActive(true); 
cam2.enabled = false;//or cam1.SetActive(false); i forgot
}
}