При нажатии пробела персонаж подпрыгивает, но если во время полета нажать еще раз пробел то он подпрыгнет выше и так пока жмем пробел. Как сделать чтобы персонаж прыгал один раз?
using UnityEngine;
using System.Collections;
public class Character : MonoBehaviour
{
[SerializeField]
private int lives = 5;
[SerializeField]
private float speed = 3.0F;
[SerializeField]
private float jumpForce = 15.0F;
private bool isGrounded = false;
new private Rigidbody2D rigidbody;
private Animator animator;
private SpriteRenderer sprite;
private void Awake()
{
rigidbody = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
sprite = GetComponentInChildren<SpriteRenderer>();
}
private void FixedUpdate()
{
CheckGround();
}
private void Update()
{
if (Input.GetButton("Horizontal")) Run(); }
private void Run()
{
Vector3 direction = transform.right * Input.GetAxis("Horizontal");
transform.position = Vector3.MoveTowards(transform.position, transform.position + direction, speed * Time.deltaTime);
sprite.flipX = direction.x < 0.0F;
}
private void Jump()
{
rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
private void CheckGround()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 0.3F);
isGrounded = colliders.Length > 1;
}
}