C# and Cinemachine — The Basics
In-game, scripts are going to be the primary method of triggering camera swaps. Let’s look at how to use C# to interact with Cinemachine!
First off, we need to add a new library to the C# script.
Now we need to get references to our cameras. The simplest way of doing this is using an array.
Recompile and back in Unity, you can drag your cameras into your array.
Now we can reference our cameras inside our script.
For a simple example, when I press the “R” key, my first camera will turn off, and Cinemachine will automatically move to the next available camera.
Camera Priority dictates which camera Cinemachine will go to next. However, it is also good practice to have only the virtual camera you need active at a time.
We can also reference anything inside of the Cinemachine camera control window with script. We need a reference to the active camera:
In Update, I add the following line, setting the FoV to 40 (from default of 60).
You can access any of the properties in the CinemachineVirtualCamera component on each camera in script, including transitions, where to look, what to follow, Aim, Noise, and transitions.
With most of the setting, I would recommend taking some time and trying them out, seeing what each does and how you can use it to improve your camera shots!