Advertisement
Guest User

Untitled

a guest
Dec 30th, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ControllerScript : MonoBehaviour
  5. {
  6.  
  7. public float maxSpeed = 10f;
  8. public bool facingRight = true;
  9. Animator anim;
  10. bool grounded = false;
  11. public bool touchingWall = false;
  12. public Transform groundCheck;
  13. public Transform wallCheck;
  14. float groundRadius = 0.2f;
  15. float wallTouchRadius = 0.2f;
  16. public LayerMask whatIsGround;
  17. public LayerMask whatIsWall;
  18. public float jumpForce = 700f;
  19. public float jumpPushForce = 10f;
  20. bool doubleJump = false;
  21. public bool hasJumped = false;
  22. public bool hasWallJumped = false;
  23. public float move = 100f;
  24.  
  25.  
  26. void Start ()
  27. {
  28. anim = GetComponent<Animator> ();
  29.  
  30. }
  31.  
  32. void FixedUpdate ()
  33. {
  34.  
  35.  
  36. grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
  37. touchingWall = Physics2D.OverlapCircle (wallCheck.position, wallTouchRadius, whatIsWall);
  38. anim.SetBool ("touchingWall", touchingWall);
  39. anim.SetBool ("Ground", grounded);
  40.  
  41.  
  42. if (grounded) {
  43. doubleJump = false;
  44. hasWallJumped = false;
  45. touchingWall = false;
  46. }
  47.  
  48.  
  49.  
  50. anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
  51.  
  52. float move = Input.GetAxis ("Horizontal");
  53.  
  54. anim.SetFloat ("Speed", Mathf.Abs (move));
  55.  
  56. rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
  57.  
  58. if (move > 0 && !facingRight)
  59. Flip ();
  60. else if (move < 0 && facingRight)
  61. Flip ();
  62.  
  63.  
  64.  
  65. if ((!grounded && touchingWall) && Input.GetButtonDown ("Jump")) {
  66. rigidbody2D.velocity = Vector2.zero;
  67. rigidbody2D.velocity = new Vector2 (maxSpeed * 10, rigidbody2D.velocity.y);
  68. }
  69.  
  70.  
  71. }
  72.  
  73. void Update ()
  74. {
  75.  
  76. if ((grounded || !doubleJump) && Input.GetButtonDown ("Jump")) {
  77. anim.SetBool ("Ground", false);
  78.  
  79. rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, 10.5f);
  80. if (!doubleJump && !grounded) {
  81. doubleJump = true;
  82. }
  83. if ((!grounded && touchingWall) && Input.GetButtonDown ("Jump")) {
  84. hasWallJumped = true;
  85. Debug.LogWarning("haswalljumped");
  86. }
  87. }
  88. }
  89.  
  90. void Flip ()
  91. {
  92. facingRight = !facingRight;
  93. Vector3 theScale = transform.localScale;
  94. theScale.x *= -1;
  95. transform.localScale = theScale;
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement