using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour {
private Rigidbody2D rb;
public float speed = 15f;
public Vector2 Up = new Vector2(0, 5000);
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown(KeyCode.Space))
{
rb.MovePosition(Up);
Debug.Log("Spacebar Pressed");
}
float x = Input.GetAxis("Horizontal") * Time.fixedDeltaTime * speed;
Vector2 newPos = rb.position + Vector2.right * x;
rb.MovePosition(newPos);
}
Do not check one time input (anything with Down or Up in the name) inside FixedUpdate. FixedUpdate usually runs at a slower rate. However the input is only true for one frame. Since FixedUpdate doesn’t run every frame it can “miss” that event.