Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerMovement : MonoBehaviour {
- public float speed = 5f;
- public float jumpPower = 8f;
- bool grounded;
- public Transform groundCheck;
- float groundedRadius = 0.2f;
- public LayerMask groundMask;
- public bool inLadder = false;
- float gravity;
- void Start()
- {
- gravity = rigidbody2D.gravityScale;
- }
- void FixedUpdate()
- {
- grounded = Physics2D.OverlapCircle (groundCheck.position, groundedRadius, groundMask);
- float x = Input.GetAxis ("Horizontal");
- rigidbody2D.velocity = new Vector2 (x * speed, rigidbody2D.velocity.y);
- if(inLadder)
- {
- float y = Input.GetAxisRaw ("Vertical");
- rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, y * speed);
- rigidbody2D.gravityScale = 0;
- }
- else
- {
- rigidbody2D.gravityScale = gravity;
- if(Input.GetButtonDown ("Jump") && grounded)
- {
- rigidbody2D.AddForce(new Vector2(0f,jumpPower),ForceMode2D.Impulse);
- }
- }
- inLadder = false;
- }
- void OnTriggerStay2D(Collider2D coll)
- {
- if(coll.collider2D.tag == "Ladder")
- {
- inLadder = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement