- Home /
Unknown Identifier "Other"... Character Movement Script
Well, I was trying to create a script which would allow my character to increase speed when a key is pressed, but in the script, it gives me this error saying that other is an unknown identifier. Any help on this? Oh, and it is written in Javascript...
var runSpeed: float = 10.4;
var runG: float = 3.6;
var regularSpeed: float = 5.2;
var regularG: float = 7.2;
private var isrunning : boolean = false;
function Update () {
if (Input.GetKey("Run")) {
Running ();
}
else (Otherwise ());
}
function Running () {
var chMotor: CharacterMotor = other.GetComponent(CharacterMotor);
if (chMotor){ // make sure CharacterMotor exists
chMotor.movement.maxForwardSpeed = runSpeed;
chMotor.movement.maxSidewaysSpeed = runSpeed;
chMotor.movement.maxBackwardsSpeed = runSpeed;
chMotor.movement.gravity = runG;
}
}
function Otherwise () {
var chMotor: CharacterMotor = other.GetComponent(CharacterMotor);
if (chMotor){
chMotor.movement.maxForwardSpeed = regularSpeed;
chMotor.movement.maxSidewaysSpeed = regularSpeed;
chMotor.movement.maxBackwardsSpeed = regularSpeed;
chMotor.movement.gravity = regularG;
}
}
If your problem is solved accept an answer.
Read this page : http://answers.unity3d.com/page/newuser.html
Please watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
I understand, but the script refuses to work. what do you mean by declare? That could be many things, like declare as a variable, or declare as a transform, float, integer, Boolean...
I don't know. Where did you get this script? it looks like a gameobject variable to me. I don't know what it should do in your game the only thing i can see is that you're trying to access it and it isn't declared anywhere. It's like you're trying to eat a cake which you didn't bake yet :)
Answer by ExTheSea · May 10, 2013 at 09:40 AM
Well you're using a variable called other but you never declare it.
Fore example in this line:
var chMotor: CharacterMotor = other.GetComponent(CharacterMotor);
Your answer
Follow this Question
Related Questions
Keeping Character From Walking Through Walls 1 Answer
My CharacterController does not walk and face in the same direction 3 Answers
Rotate character to the moving direction problems? 2 Answers
Small Project, tutorials/help needed 0 Answers
Character Controller moves forever after colliding with object 1 Answer