- Home /
Question by
TheReclaimer117 · Feb 02, 2014 at 02:07 AM ·
runningparsing errorcrouching
Why do I get a Parsing Error using this script?
var walkSpeed: float = 7; // regular speed
var crchSpeed: float = 3; // crouching speed
var runSpeed: float = 20; // run speed
private var chMotor: CharacterMotor;
private var ch: CharacterController;
private var tr: Transform;
private var height: float; // initial height
function Start(){
chMotor = GetComponent(CharacterMotor);
tr = transform;
ch = GetComponent(CharacterController);
height = ch.height;
}
function Update(){
var h = height;
var speed = walkSpeed;
if (ch.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift")){
speed = runSpeed;
}
if (Input.GetKey("c")){ // press C to crouch
h = 0.5 * height;
speed = crchSpeed; // slow down when crouching
}
chMotor.movement.maxForwardSpeed = speed; // set max speed
var lastHeight = ch.height; // crouch/stand up smoothly
ch.height = Mathf.Lerp(ch.height, h, 5*Time.deltaTime);
tr.position.y += (ch.height-lastHeight)/2; // fix vertical position
}
Comment
Best Answer
Answer by robertbu · Feb 02, 2014 at 02:22 AM
This script compiles fine for me. Note that a 'parsing error' is often either a missing '}' at the end of the file or an extra '}' at the end of the file.
Your answer
Follow this Question
Related Questions
How to make the character strafe while running? 1 Answer
code intended to instantiate 7 PathFloorUnit Prefabs,creates only one clone. 1 Answer
Does Unity app still run while app is asleep/closed 1 Answer
Maintaining Run on direction change (double tap using GetAxis) 0 Answers
Strange problem with crouch script 0 Answers