I am a beginner to unity and are using C#, and I’m trying to program a block to jump once and not linger in the air every time the jump key is pressed. Can someone give me some suggestions or tell me how to fix it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]
private float _speed = 3.5f;
[SerializeField]
private float _jump = 5;
[SerializeField]
public GameObject _laserPrefab;
// Start is called before the first frame update
void Start()
{
transform.position = new Vector3(-10.92f, -0.44f, 0);
}
// Update is called once per frame
void FixedUpdate()
{
float horizontalInput = Input.GetAxis("Horizontal");
float jumpInput = Input.GetAxis("Jump");
//Movement
if (Input.GetKey(KeyCode.Space)) ;
transform.Translate(Vector3.right * horizontalInput * _speed * Time.deltaTime);
transform.Translate(Vector3.up * jumpInput * _jump * Time.deltaTime);