- Home /
unity say's: expecting :, found '='.
i want to make a character controller, but unity sayd that the script has an error here's the script:
var walkSpeed: float = 7;
var crouchspeed: float = 3;
var runspeed: float = 15;
private var chMotor: CharacterMotor;
private var ch: CharacterController;
private var tr: Transform;
private var height: float;
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("left control"));{
h = 0.5 * height;
speed = crouchspeed;
{
chMotor.movement.maxForwardSpeed = speed;
var lastHeight = ch.height;
ch.height = Mathf.Lerp(ch.height,h,5*Time.deltaTime);
tr.position.y +=(ch.height-lastHeight)/2;
}
Unity also told you the exact line number that had the problem. What's the line number?
Answer by EHogger · Feb 11, 2013 at 09:24 PM
You've put ; on the end of the if statements which shouldn't be there. You've also missed the ; on line 31, and there is a bracket facing the wrong way on line 39.
ok thx on here, i've test it an now i can play BUT!!!! when i start the game, i can't move! i'm on one point and nothing else metter! thats a big problem that i can't go and run or crouch NOTHING! and the other error is:
UnityException: Input $$anonymous$$ey named: left control is unknown UnityEngine.Input.Get$$anonymous$$ey (System.String name) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineInput.cs:254) $$anonymous$$ove.Update () (at Assets/$$anonymous$$ove.js:35)
please help me and when you've time please write it correct i need help!
i must say the error is here UnityException: Input $$anonymous$$ey named: left control is unknown UnityEngine.Input.Get$$anonymous$$ey (System.String name) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineInput.cs:254) $$anonymous$$ove.Update () (at Assets/$$anonymous$$ove.js:35)
and the new skript
var walkSpeed: float = 7;
var crouchspeed: float = 3;
var runspeed: float = 15;
private var ch$$anonymous$$otor: Character$$anonymous$$otor;
private var ch: CharacterController;
private var tr: Transform;
private var height: float;
function Start(){
ch$$anonymous$$otor = GetComponent(Character$$anonymous$$otor);
tr = transform;
ch = GetComponent(CharacterController);
height = ch.height;
}
function Update(){
var h = height;
var speed = walkSpeed;
if(ch.isGrounded && Input.Get$$anonymous$$ey("left shift") || Input.Get$$anonymous$$ey("right shift")){
speed = runspeed;
}
if(Input.Get$$anonymous$$ey("left control")){
h = 0.5 * height;
speed = crouchspeed;
}
ch$$anonymous$$otor.movement.maxForwardSpeed = speed;
var lastHeight = ch.height;
ch.height = $$anonymous$$athf.Lerp(ch.height,h,5*Time.deltaTime);
tr.position.y +=(ch.height-lastHeight)/2;
}
Input.Getkey("left control") is wrong. It should be Input.Getkey("left ctrl") or Input.Getkey($$anonymous$$eyCode.LeftControl)
You could find this out yourself st by checking the reference manual online. The error message tells you where the problem is each time, so just look up that function and check you understand it before asking on here. http://docs.unity3d.com/Documentation/ScriptReference/Input.Get$$anonymous$$ey.html
Ins$$anonymous$$d Try using this Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftControl) this should work.
Answer by MrVarron · Feb 15, 2013 at 03:36 PM
Ok thx for the fast answer, i will try to use it (in the evening) and than i write the result, but thx on here, i hope you show my next answer and help me tomorrow or evening.... see u soon
Your answer
Follow this Question
Related Questions
errror message 1 Answer
2 errors im stuck on. 1 Answer
GUI.Box error 1 Answer
Strange error with unity. 1 Answer