Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float moveSpeed;
- private Rigidbody2D myRigidbody;
- public float jumpSpeed;
- public Transform groundCheck;
- public float groundCheckRadius;
- public LayerMask whatIsGround;
- public bool isGrounded;
- public bool onLadder;
- public float climbSpeed;
- private float climbVelocity;
- private float gravityStore;
- // Use this for initialization
- void Start () {
- myRigidbody = GetComponent<Rigidbody2D>();
- gravityStore = myRigidbody.gravityScale;
- }
- // Update is called once per frame
- void Update() {
- isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
- if (Input.GetAxisRaw("Horizontal") > 0f)
- {
- myRigidbody.velocity = new Vector3(moveSpeed, myRigidbody.velocity.y, 0f);
- } else if (Input.GetAxisRaw("Horizontal") < 0f)
- {
- myRigidbody.velocity = new Vector3(-moveSpeed, myRigidbody.velocity.y, 0f);
- } else
- {// to avoid sliding
- myRigidbody.velocity = new Vector3(0f, myRigidbody.velocity.y, 0f);
- }// jump
- if (Input.GetButtonDown("Jump") && isGrounded)
- {
- myRigidbody.velocity = new Vector3(myRigidbody.velocity.x, jumpSpeed, 0f);
- }
- if (onLadder)
- {
- myRigidbody.gravityScale = 0f;
- climbVelocity = climbSpeed * Input.GetAxisRaw("Vertical");
- myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, climbVelocity);
- }
- if (!onLadder)
- {
- myRigidbody.gravityScale = gravityStore;
- }
- //kill
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (other.tag == "KillPlane")
- {
- gameObject.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement