Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player : MonoBehaviour {
- //Floats
- public float speed = 50f;
- public float maxSpeed = 3f;
- //References
- public static Rigidbody2D rb2d;
- // Use this for initialization
- void Start ()
- {
- rb2d = gameObject.GetComponent<Rigidbody2D>();
- }
- // Update is called once per frame
- void Update ()
- {
- if (Input.GetButtonDown("Jump"))
- {
- rb2d.gravityScale *= -1;
- }
- }
- void FixedUpdate()
- {
- Vector2 easeVelocity = rb2d.velocity;
- easeVelocity.y = rb2d.velocity.y;
- easeVelocity.x *= 0.75f;
- float h = Input.GetAxisRaw("Horizontal");
- rb2d.AddForce((Vector2.right * speed) * h);
- if (rb2d.velocity.x > maxSpeed)
- {
- rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
- }
- if (rb2d.velocity.x < -maxSpeed)
- {
- rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement