topical media & game development
lib-unity-tutorial-walk-Assets-Walk-Idle-Animation.js / js
var moveComponent;
moveComponent= GetComponent(PlayerControllerMove);
var runSpeed;
runSpeed = moveComponent.runSpeed;
function Start()
{
//set all animations to loop
animation.wrapMode = WrapMode.Loop;
animation["jumpDown"].wrapMode = WrapMode.ClampForever;
animation["jumpUp"].wrapMode = WrapMode.ClampForever;
animation.Stop();
}
function Update ()
{
// The current x-z move speed (referenced from Player Controller Move script)
var moveSpeed;
moveSpeed = moveComponent.moveSpeed;
//Debug.Log(moveSpeed);
if (moveComponent.IsGrounded())
{
if( moveSpeed > .1 )
{
if( moveSpeed >= (runSpeed -3) )
animation.CrossFade("run");
else
animation.CrossFade("walk");
}
else
{
animation.CrossFade("idle");
}
} //ends if statement IsGrounded
else
{
if (moveComponent.IsJumping () )
{
if (moveComponent.HasJumpReachedApex ())
animation.CrossFade("jumpDown");
else
animation.CrossFade("jumpUp");
}
}
} //ends function update
@script RequireComponent(CharacterController)
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.