Skip to content

Instantly share code, notes, and snippets.

@ozw-sei
Created September 15, 2015 04:58
Show Gist options
  • Save ozw-sei/4eb254b99fb851c2e6a1 to your computer and use it in GitHub Desktop.
Save ozw-sei/4eb254b99fb851c2e6a1 to your computer and use it in GitHub Desktop.
#pragma strict
public var speed : float = 3; public var jumpPower : float = 6;
private var direction : Vector3 = Vector3.zero;
private var playerController : CharacterController;
private var animator : Animator;
function Start() {
playerController = GetComponent( CharacterController );
animator = GetComponentInChildren( Animator );
}
function Update() {
if( playerController.isGrounded ) {
var inputX : float = Input.GetAxis( "Horizontal" );
var inputY : float = Input.GetAxis( "Vertical" );
var inputDirection : Vector3 = Vector3( inputX, 0, inputY ); direction = Vector3.zero;
if( inputDirection.magnitude > 0.1 ) {
transform.LookAt( transform.position + inputDirection ); direction += transform.forward * speed;
animator.SetFloat( "Speed", direction.magnitude );
} else {
animator.SetFloat( "Speed", 0 );
}
if( Input.GetButton("Jump") ) {
direction.y += jumpPower;
}
}
direction.y += Physics.gravity.y * Time.deltaTime;
playerController.Move( direction * Time.deltaTime ); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment