I’m making a 2D platformer but I run into a bit of a problem, if you press the jump key repeatedly when the character is in mid-air, it will keep jumping. I only want the character to jump when it’s making contact with the floor or a wall. Here’s my code:
using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour {
public float playerSpeed = 5.0f;
public float glideSpeed = 2.5f;
// Use this for initialization
void Start () {
//PlayerSpawnPoint
transform.position = new Vector3(0, 0, 0);
Physics.gravity = new Vector3(0, -1.0F, 0);
}
// Update is called once per frame
void Update () {
//Player Movement, left and right using arrow keys
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime);
transform.Translate (Vector3.up * Input.GetAxis("Jump") * playerSpeed * Time.deltaTime);
}
}