engine: unity
coding language: c#
I am trying to control CinemachineFreeLook maxSpeed from another script in the struct AxisStat: public AxisState(float minValue, float maxValue, bool wrap, bool rangeLocked, float maxSpeed, float accelTime, float decelTime, string name, bool invert)
It only accepts to type a number, but not a variable.
Whenever I create a public float variable and place it in maxSpeed, it keeps sending the error: error CS0236: A field initializer cannot reference the non-static field, method, or property 'CinemachineFreeLook.rSpeed'
Here is the default unity CinemachineFreeLook script code + the added code which I declare a float variable "rSpeed" at the beginning and added my variable in the AxisStat maxSpeed:
public class CinemachineFreeLook : CinemachineVirtualCameraBase
{
public float rSpeed = 300f;
/// <summary>Object for the camera children to look at (the aim target)</summary>
[Tooltip("Object for the camera children to look at (the aim target).")]
[NoSaveDuringPlay]
public Transform m_LookAt = null;
/// <summary>Object for the camera children wants to move with (the body target)</summary>
[Tooltip("Object for the camera children wants to move with (the body target).")]
[NoSaveDuringPlay]
public Transform m_Follow = null;
/// <summary>If enabled, this lens setting will apply to all three child rigs, otherwise the child rig lens settings will be used</summary>
[Tooltip("If enabled, this lens setting will apply to all three child rigs, otherwise the child rig lens settings will be used")]
[FormerlySerializedAs("m_UseCommonLensSetting")]
public bool m_CommonLens = true;
/// <summary>Specifies the lens properties of this Virtual Camera.
/// This generally mirrors the Unity Camera's lens settings, and will be used to drive
/// the Unity camera when the vcam is active</summary>
[FormerlySerializedAs("m_LensAttributes")]
[Tooltip("Specifies the lens properties of this Virtual Camera. This generally mirrors the Unity Camera's lens settings, and will be used to drive the Unity camera when the vcam is active")]
[LensSettingsProperty]
public LensSettings m_Lens = LensSettings.Default;
/// <summary> Collection of parameters that influence how this virtual camera transitions from
/// other virtual cameras </summary>
public TransitionParams m_Transitions;
/// <summary>Legacy support</summary>
[SerializeField] [HideInInspector]
[FormerlySerializedAs("m_BlendHint")]
[FormerlySerializedAs("m_PositionBlending")] private BlendHint m_LegacyBlendHint;
/// <summary>The Vertical axis. Value is 0..1. Chooses how to blend the child rigs</summary>
[Header("Axis Control")]
[Tooltip("The Vertical axis. Value is 0..1. Chooses how to blend the child rigs")]
[AxisStateProperty]
public AxisState m_YAxis = new AxisState(0, 1, false, true, 2f, 0.2f, 0.1f, "Mouse Y", false);
/// <summary>Controls how automatic recentering of the Y axis is accomplished</summary>
[Tooltip("Controls how automatic recentering of the Y axis is accomplished")]
public AxisState.Recentering m_YAxisRecentering = new AxisState.Recentering(false, 1, 2);
/// <summary>The Horizontal axis. Value is -180...180. This is passed on to the rigs' OrbitalTransposer component</summary>
[Tooltip("The Horizontal axis. Value is -180...180. This is passed on to the rigs' OrbitalTransposer component")]
[AxisStateProperty]
public AxisState m_XAxis = new AxisState(-180, 180, true, false, rSpeed, 0.1f, 0.1f, "Mouse X", true);