Control Your Virtual Camera from Script- Game Dev Series 173

Objective: get control of Cinemachine with C#.

Now we knew the basic of using virtual camera from Cinemachine, the next part would be get a fully control by script. This would be the main goal of using Cinemachine if you wish to control your camera with input system of Unity.

Get the access of using Cinemachine

The first step of take control of Cinemachine is get the library of Cinemachine from script.
At the top of your script, using “Cinemachine” to access the library.

Then depend on what object we use from Cinemachine to call the proper component from script.

Take control of everything

To find out how to control every single element under a virtual camera(or any other objects from Cinemachine) is not that hard. You can find out all the names or options from Inspector of Editor. Or you can search for the documentation of Unity to dig out more function.

For example, if I want to change the target of Look At from virtual camera, I can simply access it from script.

If I want to change the field of view from script, I can first take a look at Inspector to make sure the name of option.

Then try to call it from script.

It would be much easier to find out how to call it.

With these, you can easily create a camera controlling system from script to get a fully control of camera in your game.



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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.