Spacebar not working consistently in Unity
21. Srpen 2024 v 00:42
Sometimes it works but sometimes it just doesn't. Maybe it has something to do with gravity or drag?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public float flapStrenght;
// Start is called before the first frame update (plays ony once)
void Start()
{
gameObject.name = "Roger";
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true)
{
myRigidbody.velocity = Vector2.up * flapStrenght;
}
}
}