I’m trying to have my character change from a normal walk speed to a sprinting speed but I’m getting a console error that reads: "An instance of type ‘UnityEngine.CharacterController’ is required to access non static member ‘isGrounded’. I’m extremely new to Unity and scripting in general so I’m not really sure what this means or how to go about fixing it. I have my script in the inspector underneath my First Person Controller. Any insight would be helpful.
var walkSpeed : float = 7; //Regular Speed
var sprintSpeed : float = 13; //Running speed.
private var charMotor : CharacterMotor;
private var charController : CharacterController;
function Start ()
{
charMotor = GetComponent(CharacterMotor);
charController = GetComponent(CharacterController);
}
function Update ()
{
//Makes the speed variable.
var speed = walkSpeed;
//Checking if sprint is allowed.
if(CharacterController.isGrounded && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
{
//Changing speed to sprint.
speed = sprintSpeed;
}
charMotor.movement.maxForwardSpeed = speed; //Setting speed.
}