using System.Collections; using System.Collections.Generic; using UnityEngine; public class DragonMovement : MonoBehaviour { [SerializeField] KeyCode FlapKey; Rigidbody2D _rigidbody; float _flapTime = 0f; [SerializeField] float FlapForce = 300f; [SerializeField] float FlapLength = .25f; void Start() { _rigidbody = this.GetComponent(); } private void Update() { if (Input.GetKeyDown(FlapKey)) { _flapTime = FlapLength; } } void FixedUpdate() { if (_flapTime > 0f) { _rigidbody.AddForce(new Vector2(0f, FlapForce)); } _flapTime -= Time.deltaTime; } }