I’m a complete beginner to coding but I’m working on a game in 2D where you’re a square. Now it’s very small and I just started working on the square’s movement script…
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float speed = 1F;
public float jump = 1F;
void Start () {
}
void Update () {
if (Input.GetKey(KeyCode.D))
transform.position += new Vector3(speed + Time.deltaTime, 0F, 0F);
if (Input.GetKey(KeyCode.A))
transform.position -= new Vector3(speed + Time.deltaTime, 0F, 0F);
if (Input.GetKey(KeyCode.Space))
GetComponent<Rigidbody>().AddForce(new Vector2(0, 1), ForceMode.Impulse);
}
}
How do I make it so that this doesn’t just jump whenever I hit spacebar? I don’t understand how to make it check at all so if you guys could give me just an edited, fully working version of my script, that would be amazing. Thanks in advance!
Using Unity 5 so please nothing that will be obsolete!