Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movement : MonoBehaviour {
- public Rigidbody2D rb;
- public float speed = 7f;
- public float jumpPower = 300f;
- bool onGround;
- void Start() {
- }
- void Update() {
- float x = Input.GetAxis("Horizontal");
- rb.velocity = new Vector2(speed * x, rb.velocity.y);
- if (x > 0) {
- transform.eulerAngles = new Vector3(0,0,0);
- } else if (x < 0) {
- transform.eulerAngles = new Vector3(0,180,0);
- }
- if (Input.GetButtonDown("Jump") && onGround) {
- rb.AddForce(Vector2.up * jumpPower);
- onGround = false;
- }
- }
- void OnCollisionEnter2D(Collision2D c) {
- onGround = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement