How to make one jump in a unit?

  • 0
    Made a script for the main character, but if you press the space bar all the time, then it flies out of the map, how to make a single jump? Here is the script.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class perss: MonoBehaviour {

    Rigidbody2D rb;

    void Start () {

    rb = GetComponent ();
    }

    void Update () {
    if (Input.GetKeyDown (KeyCode.Space)) {
    pipirka ();
    }
    }

    void FixedUpdate () {

    rb.velocity = new Vector2 (Input.GetAxis ("Horizontal") * 9f, rb.velocity.y);
    }

    void pipirka () {

    rb.AddForce (transform.up * 7f, ForceMode2D.Impulse);
    }

    void Reload () {
    Application.LoadLevel (Application.loadedLevel);
    }
    }
    Unity Game Engine Anonymous, Jun 13, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!