Created
August 25, 2014 04:05
-
-
Save jquave/345e16eb23b87a00bd71 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| void Update() { | |
| Vector2 newVel = new Vector3(walkSpeed * input.horizontal, rigidbody2D.velocity.y); | |
| rigidbody2D.velocity = newVel; | |
| /* Use jumpPressed to start a jump so they have to press it *while* being canJump is true */ | |
| if(input.jumpPressed && canJump) { | |
| rigidbody2D.velocity = new Vector2(0,jumpForce); | |
| if(jumpClips!=null & jumpClips.Length>0) { | |
| AudioClip jumpClip = jumpClips[ Mathf.FloorToInt( Random.Range(0,jumpClips.Length-1) ) ]; | |
| audio.PlayOneShot(jumpClip); | |
| } | |
| canJump = false; | |
| timeJumped = Time.time; | |
| } | |
| else { | |
| // We may be mid-jump here, which means we want to keep moving the player up while they hold the jump button, on a curve that falls off | |
| if(!input.jumpDown && rigidbody2D.velocity.y>0) { | |
| // We're moving upward and the player let go of the button, slow their jump | |
| rigidbody2D.velocity = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y - Time.deltaTime*30, 0); | |
| } | |
| } | |
| UpdateAnims(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment