Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. public class Jump : MonoBehaviour
  6. {
  7. public string jumpButton = "Fire1";
  8. public float jumpPower = 10.0f;
  9. public Animator anim;
  10. public bool grounded = false;
  11. public float minJumpDelay = 0.5f;
  12. public Transform groundCheck;
  13. private float jumpTime = 0.0f;
  14. private bool jumped = false;
  15.  
  16.  
  17. void Start (){
  18. }
  19.  
  20. void Update (){
  21. grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
  22. jumpTime -= Time.deltaTime;
  23. if(Input.GetButtonDown(jumpButton) && grounded)
  24. {
  25. jumped = true;
  26. grounded = false;
  27. }
  28. if (jumped == true) // check if jump is true
  29. jump();
  30. }
  31.  
  32. void jump (){
  33. if (jumped == true) // double check jump is true
  34. anim.SetTrigger("Jump");
  35. rigidbody2D.AddForce(transform.up*jumpPower);
  36. jumpTime = minJumpDelay;
  37. anim.SetTrigger("Jump");
  38. rigidbody2D.AddForce(transform.up*jumpPower);
  39. jumpTime = minJumpDelay;
  40. if(grounded == false && jumpTime <= 0 && jumped)
  41. jumped = false;
  42. fall();
  43. }
  44.  
  45. void land (){
  46. jumped = false;
  47. anim.SetTrigger("Land");
  48. grounded = true;
  49. }
  50.  
  51. void fall (){
  52. {
  53. anim.SetTrigger("Fall");
  54. }
  55. if(grounded)
  56. {
  57. anim.SetTrigger("Fall_Land");
  58. if(grounded == false && jumpTime <= 0 && jumped)
  59. land();
  60. }
  61. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement