Hi. So I want to make clickalbe buttons that changes variables. I have following code:
var walkSpeed = PlatformerControllerMovement.walkSpeed;
var runSpeed = PlatformerControllerMovement.runSpeed;
var inAirControlAcceleration = PlatformerControllerMovement.runSpeed;
var gravity = PlatformerControllerMovement.gravity;
var maxFallSpeed = PlatformerControllerMovement.maxFallSpeed;
var speedSmooth = PlatformerControllerMovement.speedSmoothing;
var rotateSmooth = PlatformerControllerMovement.rotationSmoothing;
var height = PlatformerControllerJumping.height;
var extraHeight = PlatformerControllerJumping.extraHeight;
var doubleJumpHeight = PlatformerControllerJumping.doubleJumpHeight;
function OnGUI () {
chooseButton(0,0,"walkSpeed", walkSpeed);
chooseButton(1,0,"runSpeed", runSpeed);
chooseButton(2,0,"inAirCtrlAcc", inAirControlAcceleration);
chooseButton(3,0,"gravity", gravity);
chooseButton(4,0,"maxFallSpeed", maxFallSpeed);
chooseButton(5,0,"speedSmooth", speedSmooth);
chooseButton(6,0,"rotateSmooth", rotateSmooth);
chooseButton(0,1,"hate", height);
chooseButton(1,1,"extraHate", extraHeight);
chooseButton(2,1,"doubleHate", doubleJumpHeight);
}
function chooseButton (posX, posY, variableName, variableObj){
GUI.Box(Rect (10+(posX*95),10+(posY*85),90,55), variableName);
if (GUI.RepeatButton (Rect (25+(posX*95), 33+(posY*85), 25, 25), "-")) {
variableObj -= 0.1;
}
if (GUI.RepeatButton (Rect (60+(posX*95), 33+(posY*85), 25, 25), "+")) {
variableObj += 0.1;
}
GUI.Box(Rect (10+(posX*95),68+(posY*85),90,22), variableObj.ToString());
}
...and when i click button "-" or "+" nothing happens. I noticed, then if i will extend code from a function and type variables by hand - everything works! There is a webdemo, if somebody want to see it in action: click here.