Hi,
I’m trying to make a top down camera controller with the help of Cinemachine for a game.
I want to access some of the properties as seen in the inspector.
I’m relatively new to programming and i think i’m just missing something that should be simple.
In the Virtual Camera component there are a few options that I can change, but not all and not the ones i want to adjust in a script.
I found the documentation of the Cinemachine API and found it works with Structs which I’m trying to get my head around and how they differ from classes.
The struct AxisState has some of the values i would like to adjust in my script.
https://docs.unity3d.com/Packages/com.unity.cinemachine@2.1/api/Cinemachine.AxisState.html
Maybe I just need to get a bit more knowledge before diving in, but my main goal atm is to learn.
i just try to modify the behavior of the camera with the middle mouse button for now, but the functionality will be different in the end, but I just don’t understand the syntax for accessing a struct and manipulating the values.
Any help to guide me in the right direction is much appreciated!
Here is my code so far (with the error i get when i try to run it below), I added this script to the Gameobject that has the virtual camera:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CameraControlTopDown : MonoBehaviour
{
AxisState axisState;
// Start is called before the first frame update
void Start()
{
axisState = GetComponent<AxisState>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(2))
{
axisState.m_InputAxisName = "Mouse X";
}
if (Input.GetMouseButtonUp(2))
{
axisState.m_InputAxisName = null;
}
}
}
Error:
ArgumentException: GetComponent requires that the requested component ‘AxisState’ derives from MonoBehaviour or Component or is an interface.
UnityEngine.Component.GetComponentInChildren (System.Type t, System.Boolean includeInactive) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Component.bindings.cs:55)
UnityEngine.Component.GetComponentInChildren[T] () (at C:/buildslave/unity/build/Runtime/Export/Scripting/Component.bindings.cs:72)
CameraControlTopDown.Start () (at Assets/CameraControlTopDown.cs:15)