- Home /
Question by
smirlianos · Dec 17, 2012 at 07:29 PM ·
variablesaccessothercharactermotor
Why i can not access these variables?
I have these lines in a script
var varscript : CharacterMotor;
function OnTriggerStay (other : Collider) {
varscript.maxForwardSpeed --;
varscript.maxSidewaysSpeed --;
varscript.maxBackwardsSpeed --;
}
that access the variables from the CharacterMotor.js But it gives me this error.
Expression 'self.varscript.maxForwardSpeed' cannot be assigned to.
What daoes the "self" mean? I don't understand
Thanks in advance!
Comment
if your script is on the same object that your charactermotor is on, maybe try GetComponent() ins$$anonymous$$d of just using a public variable
"self" means "this script". So it says that the variable on "this scripts varscripts maxForwardSpeed" can't be assigned to (written to). This is because it doesn't exist.
Best Answer
Answer by Statement · Dec 17, 2012 at 08:12 PM
It looks like there is no maxForwardSpeed on CharacterMotor. However CharacterMotorMovement has it.
#pragma strict
var varscript : CharacterMotor;
function OnTriggerStay (other : Collider) {
varscript.movement.maxForwardSpeed --;
varscript.movement.maxSidewaysSpeed --;
varscript.movement.maxBackwardsSpeed --;
}