So i have this basic 2D player code that can jump and move horizontally but the jump can always be initiated, even when already in air. How do i fix this? Code here:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour{
public float moveSpeed = 10f;
public float jumpSpeed = 10f;
void Update () {
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
if (Input.GetButtonDown ("Jump")){
rigidbody2D.velocity = new Vector3(0, jumpSpeed, 0);
}
transform.Translate (new Vector3 (h, 0));
}
}
↧