Код
var controller : CharacterController;
var oldHeight;
var flagStand = false;
var dist;
function Start ()
{
controller = GetComponent(CharacterController);
oldHeight = controller.height;
dist = oldheight / 4 ; //вообще - (oldheight - controller.height) / 2, но т.к. controller.height == oldheight / 2, то получаем это
}
function Update()
{
if(flagStand && !Physics.Raycast (transform.position, Vector2.up, oldheight / 2))
{
StandUp();
flagStand = false;
}
if (Input.GetKey(KeyCode.LeftControl)) Squatting();
if (Input.GetKeyUp (KeyCode.LeftControl) )
{
if(!Physics.Raycast (transform.position, Vector2.up, oldheight / 2)) StandUp();
else flagStand = true;
}
}
function StandUp()
{
controller.height = oldHeight;
transform.position.y = transform.position.y + dist + 0.01f
}
functoin Squatting()
{
controller.height = controller.height / 2;
transform.position.y = transform.position.y - dist + 0.01f;
}
Обсуждалось тут:
Так, ссылка запрещена, так что думайте сами