diff --git a/unity/Assets/Scripts/DragonMovement.cs b/unity/Assets/Scripts/DragonMovement.cs index b7e361d..2c4e452 100644 --- a/unity/Assets/Scripts/DragonMovement.cs +++ b/unity/Assets/Scripts/DragonMovement.cs @@ -21,7 +21,8 @@ public class DragonMovement : MonoBehaviour [SerializeField] List _ammoGui2 = new List(); [SerializeField] GameObject _ammoNormal; [SerializeField] GameObject _ammoGlide; - const float GLIDE_TIME = 0.6f; + const float DIVE_TIME = 0.4f; + float _buttonHoldTime = 0f; ArrayList _ghosts = new ArrayList(); float _stunTime = 0f; @@ -32,6 +33,7 @@ public class DragonMovement : MonoBehaviour int _ammo = 0; float _speedBoostTime = 0f; float _timeToUpdateGhosts = 0f; + bool _isInDive = false; public enum AttackType { @@ -149,6 +151,7 @@ public class DragonMovement : MonoBehaviour void Stun(float length) { + _isInDive = false; _stunTime = length; _animator.Play("fall"); ShowNormalAmmo(); @@ -212,6 +215,12 @@ public class DragonMovement : MonoBehaviour _ammoGlide.SetActive(false); } + void NormalFlight() + { + _animator.Play("glide"); + ShowNormalAmmo(); + } + void Shoot() { if (Ammo <= 0) @@ -256,22 +265,41 @@ public class DragonMovement : MonoBehaviour _flapTime -= Time.deltaTime; _stunTime -= Time.deltaTime; + if (Input.GetKey(FlapKey)) + { + _buttonHoldTime += Time.deltaTime; + } + else + { + _buttonHoldTime = 0f; + } + const float SPEED = .4f; float horizontalSpeed = SPEED; float verticalSpeed = 0f; - if (_flapTime < - GLIDE_TIME) + if (_buttonHoldTime >= DIVE_TIME) { - _ammoNormal.SetActive(false); - _ammoGlide.SetActive(true); - _animator.Play("speedup"); - horizontalSpeed += (_flapTime + GLIDE_TIME) * -2f; + if (_isInDive == false) + { + _isInDive = true; + _ammoNormal.SetActive(false); + _ammoGlide.SetActive(true); + _animator.Play("speedup"); + _rigidbody.velocity = new Vector2(_rigidbody.velocity.x, 0f); + _rigidbody.AddForce(new Vector2(FlapForce * .1f, FlapForce * -5.5f)); + } + horizontalSpeed += (_buttonHoldTime) * 3f; } else { - // + if (_isInDive) + { + NormalFlight(); + _isInDive = false; + } } @@ -312,7 +340,7 @@ public class DragonMovement : MonoBehaviour void UpdateGhosts() { - if (_flapTime >= - GLIDE_TIME) + if (_isInDive == false) { foreach (GameObject ghost in _ghosts) {