I have acquired C# versions of all the first person controller scripts. Each script has the letter “C” on the end of it’s name to distinguish it from the javascript versions. I also have a script that allows the player to crouch. It works in javascript but because I don’t code in java I need to convert it to C#. I have done this, but I am getting an error when referencing the C# version of the character motor. This is the code:
using UnityEngine;
using System.Collections;
public class CrouchC : MonoBehaviour {
public float walkSpeed = 7.0F;
public float crouchSpeed = 3.0F;
public float runSpeed = 20.0F;
private CharacterMotorC chMotor;
private Transform tr;
private float dist;
void Start(){
chMotor = GetComponent(CharacterMotorC);
tr = transform;
CharacterController ch = GetComponent (CharacterController);
dist = ch.height / 2;
}
void Update(){
float vScale = 1.0F;
float speed = walkSpeed;
if (chMotor.grounded && Input.GetKey ("left shift") || Input.GetKey ("right shift")) {
speed = runSpeed;
}
if (Input.GetKey ("right shift")) {
vScale = 0.35F;
speed = crouchSpeed;
}
chMotor.movement.maxForwardSpeed = speed;
float ultScale = tr.localScale.y;
tr.localScale.y = Mathf.Lerp (tr.localScale.y, vScale, 5 * Time.deltaTime);
tr.position.y += dist * (tr.localScale.y - ultScale);
}
}
The error is on line 14 and is error code CS0119. I don’t know how to solve this, I’ve tried everything! Someone please help?