- Home /
Switching between cameras by C# with animation.
Can I make switching between 2 cameras with basic animation like floating using C#?
you mean smooth transition between what the cameras are showing?
Answer by tormentoarmagedoom · Sep 22, 2017 at 07:30 AM
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 :D
BYE !
Answer by NorthStar79 · Sep 22, 2017 at 08:11 AM
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.
Answer by NinjaEntertainment · Sep 22, 2017 at 08:12 PM
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
}
}
Your answer
Follow this Question
Related Questions
switching cameras C# 4 Answers
Camera switching : C# onTriggerEnter not working 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Switch Camera on Input in C# 3 Answers