Advertisement
Maniklas

Game JAm

Mar 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Playercontroller : MonoBehaviour
  6. {
  7.  
  8.     public float speed;
  9.     private float jumpforce = 10.0f;
  10.     public float jumppower = 10.0f;
  11.     private Rigidbody2D rb2d;
  12.     private Vector2 Jump;
  13.     private bool groundcheck = true;
  14.  
  15.     // Use this for initialization
  16.     void Start()
  17.     {
  18.         rb2d = GetComponent<Rigidbody2D>();
  19.         Jump = new Vector2(0.0f, jumppower);
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void FixedUpdate ()
  24.     {
  25.  
  26.         float moveHorizontal = Input.GetAxis("Horizontal");
  27.  
  28.         Vector2 movement = new Vector2(moveHorizontal, 0);
  29.  
  30.         if ((Input.GetKeyDown(KeyCode.Space) && groundcheck == true)|| (Input.GetAxis("Vertical") > 0 && groundcheck == true))
  31.         {
  32.             groundcheck = false;
  33.             jump();
  34.         }
  35.  
  36.         if (rb2d.velocity.y == 0)
  37.         {
  38.             groundcheck = true;
  39.         }
  40.         rb2d.AddForce(movement * speed);
  41.  
  42.     }
  43.  
  44.     private void jump()
  45.     {
  46.         print("jump");
  47.         rb2d.AddForce(Jump * jumpforce);
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement