Created
September 15, 2015 04:58
-
-
Save ozw-sei/4eb254b99fb851c2e6a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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