Advertisement
Guest User

Untitled

a guest
Sep 19th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.  
  6.     //Floats
  7.     public float speed = 50f;
  8.     public float maxSpeed = 3f;
  9.     //References
  10.     public static Rigidbody2D rb2d;
  11.  
  12.     // Use this for initialization
  13.     void Start ()
  14.     {
  15.         rb2d = gameObject.GetComponent<Rigidbody2D>();
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update ()
  20.     {
  21.         if (Input.GetButtonDown("Jump"))
  22.         {
  23.             rb2d.gravityScale *= -1;
  24.         }
  25.     }
  26.     void FixedUpdate()
  27.     {
  28.         Vector2 easeVelocity = rb2d.velocity;
  29.         easeVelocity.y = rb2d.velocity.y;
  30.         easeVelocity.x *= 0.75f;
  31.         float h = Input.GetAxisRaw("Horizontal");
  32.         rb2d.AddForce((Vector2.right * speed) * h);
  33.  
  34.         if (rb2d.velocity.x > maxSpeed)
  35.         {
  36.             rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
  37.         }
  38.  
  39.         if (rb2d.velocity.x < -maxSpeed)
  40.        {
  41.            rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
  42.        }
  43.          
  44.    }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement