Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour {
  5.  
  6. public float moveSpeed;
  7. private Rigidbody2D myRigidbody;
  8. public float jumpSpeed;
  9.  
  10. public Transform groundCheck;
  11. public float groundCheckRadius;
  12. public LayerMask whatIsGround;
  13.  
  14. public bool isGrounded;
  15.  
  16. public bool onLadder;
  17. public float climbSpeed;
  18. private float climbVelocity;
  19. private float gravityStore;
  20.  
  21. // Use this for initialization
  22. void Start () {
  23. myRigidbody = GetComponent<Rigidbody2D>();
  24. gravityStore = myRigidbody.gravityScale;
  25. }
  26.  
  27. // Update is called once per frame
  28. void Update() {
  29.  
  30. isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
  31.  
  32. if (Input.GetAxisRaw("Horizontal") > 0f)
  33. {
  34. myRigidbody.velocity = new Vector3(moveSpeed, myRigidbody.velocity.y, 0f);
  35. } else if (Input.GetAxisRaw("Horizontal") < 0f)
  36. {
  37. myRigidbody.velocity = new Vector3(-moveSpeed, myRigidbody.velocity.y, 0f);
  38. } else
  39. {// to avoid sliding
  40. myRigidbody.velocity = new Vector3(0f, myRigidbody.velocity.y, 0f);
  41. }// jump
  42. if (Input.GetButtonDown("Jump") && isGrounded)
  43. {
  44. myRigidbody.velocity = new Vector3(myRigidbody.velocity.x, jumpSpeed, 0f);
  45. }
  46. if (onLadder)
  47. {
  48. myRigidbody.gravityScale = 0f;
  49. climbVelocity = climbSpeed * Input.GetAxisRaw("Vertical");
  50. myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, climbVelocity);
  51. }
  52. if (!onLadder)
  53. {
  54. myRigidbody.gravityScale = gravityStore;
  55. }
  56. //kill
  57.  
  58. }
  59. void OnTriggerEnter2D(Collider2D other)
  60. {
  61. if (other.tag == "KillPlane")
  62. {
  63. gameObject.SetActive(false);
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement