I tried many buttons but I can't connect them with the (Java)Script.
So I made 2 gui buttons: one for jump which was easy because I have an if
statement and if it's true
then jump.
But I have problems with the crouch button. Bellow is my script but I can't figure out how I can do this from Update in function Gui.
(Or if you know how to connect buttons with JS functions, please tell me: it's always a better option :D )
This is my script:
#pragma strict
private var tr: Transform;
private var dist: float; // distance to ground
function Start(){
tr = transform;
var ch:CharacterController = GetComponent(CharacterController);
dist = ch.height/2; // calculate distance to ground
}
function Update()
{
var vScale = 1.0;
if (Input.GetKey("s")){
vScale = 0.5;
}
var ultScale = tr.localScale.y;
tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
tr.position.y += dist * (tr.localScale.y-ultScale);
}
function OnGUI ()
{
if(GUI.Button(new Rect(15, 330, 200, 100), "Shrink"))
{
}
}
#pragma strict
? This is for Unity, right? \$\endgroup\$5*Time.deltaTime
. This value never approaches 1, so the character is never fully crouched. \$\endgroup\$