I am trying to make a script to move a ball(the main character) and he moves to right and left without problems or errors, but dont jump. Here is the code:
using UnityEngine;
using System.Collections;
public class MovementScript: MonoBehaviour {
//Variables
public GameObject player;
public Rigidbody2D rb2d;
public float velocity= 1;
public float jumpForce= 3;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
Movement();
}
//Movement
void Movement(){
//Jump
if(Input.GetKey("space")){
rb2d.AddForce(Vector2.up * jumpForce);
}
//Move to left
if(Input.GetKey("a")){
rb2d.AddForce(Vector2.left * velocity);
}
//Move to right
if(Input.GetKey("d")){
rb2d.AddForce(Vector2.right * velocity);
}
}
}