Not sure if this is what you are asking or not, but this is a shot in the dark.
#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;
}
/I ADDED THIS BIT*************
//What this does is checks each time Update() is called if the 'c' key was hit.
//If you are pressing the crouch key, then run the crouch function.
if(Input.GetKeyUp("c")){
crouch();
}
/END OF EDIT*****************
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"))
{
/* I ADDED THIS BIT*******************************
//When you press a button the player crouches.
crouch();
/END OF EDIT************************************
}
}
/I ADDED THIS BIT***********************
//This is the function that is run when you either press 'C' or press a gui button.
function crouch(){
//make character crouch here
//this is run once when the "Shrink Button" is pressed.
//this is also done once when the c button is pressed.
//Right not this only logs that the player is crouching. Additional logic will be needed for your character to actually crouch.
Debug.Log("Crouch Button Pressed!");
}
/END OF EDIT****************************