You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
713 B

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<Rigidbody2D>();
}
private void Update()
{
if (Input.GetKeyDown(FlapKey))
{
_flapTime = FlapLength;
}
}
void FixedUpdate()
{
if (_flapTime > 0f)
{
_rigidbody.AddForce(new Vector2(0f, FlapForce));
}
_flapTime -= Time.deltaTime;
}
}