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 Playercontroller : MonoBehaviour
- {
- public float speed;
- private float jumpforce = 10.0f;
- public float jumppower = 10.0f;
- private Rigidbody2D rb2d;
- private Vector2 Jump;
- private bool groundcheck = true;
- // Use this for initialization
- void Start()
- {
- rb2d = GetComponent<Rigidbody2D>();
- Jump = new Vector2(0.0f, jumppower);
- }
- // Update is called once per frame
- void FixedUpdate ()
- {
- float moveHorizontal = Input.GetAxis("Horizontal");
- Vector2 movement = new Vector2(moveHorizontal, 0);
- if ((Input.GetKeyDown(KeyCode.Space) && groundcheck == true)|| (Input.GetAxis("Vertical") > 0 && groundcheck == true))
- {
- groundcheck = false;
- jump();
- }
- if (rb2d.velocity.y == 0)
- {
- groundcheck = true;
- }
- rb2d.AddForce(movement * speed);
- }
- private void jump()
- {
- print("jump");
- rb2d.AddForce(Jump * jumpforce);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement