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;
- public LayerMask groundMask;
- public Transform groundCheck;
- float groundedRadius = .2f;
- bool grounded;
- void Update()
- {
- grounded = Physics2D.OverlapCircle(groundCheck.position, groundedRadius, groundMask);
- float x = Input.GetAxis ("Horizontal");
- rigidbody2D.velocity = new Vector2 (speed * x, rigidbody2D.velocity.y);
- if(Input.GetButtonDown("Jump") && grounded)
- {
- rigidbody2D.AddForce(new Vector2(0f,jumpPower), ForceMode2D.Impulse);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement