Working with Cinemachine

How to access Cinemachine Virtual Camera’s component via C#

Now that we have our camera’s setup and can toggle them on and off via C# script, it is time to learn how we can also access the internal components of the Virtual Camera via script as well.

In this short article we are explore how we can access most of the virtual camera settings such as Field of View, Near Clip Plane or even the Dutch rotation.

How to access Virtual Camera Components:

To start scripting with Cinemachine, we first need to gain access to the Cinemachine Library. This can be done by using the “using Cinemachine” on the top.

Once you have that done, we need to create an local variable so we can gain access to the actual cinemachine component.

In the start method we need to assign the virtual machine to our local variable, then we can gain access to everything within that component. Below are two example which alters the Priority and the Field of view of this particular virtual camera at start run time.

As long as you have the Cinemachine library you are able to change anything within that component as long as you have access to it. For example, if your player character triggers and collider that needs their FOV changed from really close to really far, we can do so with C# script just by following the example above.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.