Browse Source

hold button to dive

master
Josh 2 years ago
parent
commit
bdeb0c05b2
  1. 44
      unity/Assets/Scripts/DragonMovement.cs

44
unity/Assets/Scripts/DragonMovement.cs

@ -21,7 +21,8 @@ public class DragonMovement : MonoBehaviour
[SerializeField] List<SpriteRenderer> _ammoGui2 = new List<SpriteRenderer>(); [SerializeField] List<SpriteRenderer> _ammoGui2 = new List<SpriteRenderer>();
[SerializeField] GameObject _ammoNormal; [SerializeField] GameObject _ammoNormal;
[SerializeField] GameObject _ammoGlide; [SerializeField] GameObject _ammoGlide;
const float GLIDE_TIME = 0.6f; const float DIVE_TIME = 0.4f;
float _buttonHoldTime = 0f;
ArrayList _ghosts = new ArrayList(); ArrayList _ghosts = new ArrayList();
float _stunTime = 0f; float _stunTime = 0f;
@ -32,6 +33,7 @@ public class DragonMovement : MonoBehaviour
int _ammo = 0; int _ammo = 0;
float _speedBoostTime = 0f; float _speedBoostTime = 0f;
float _timeToUpdateGhosts = 0f; float _timeToUpdateGhosts = 0f;
bool _isInDive = false;
public enum AttackType public enum AttackType
{ {
@ -149,6 +151,7 @@ public class DragonMovement : MonoBehaviour
void Stun(float length) void Stun(float length)
{ {
_isInDive = false;
_stunTime = length; _stunTime = length;
_animator.Play("fall"); _animator.Play("fall");
ShowNormalAmmo(); ShowNormalAmmo();
@ -212,6 +215,12 @@ public class DragonMovement : MonoBehaviour
_ammoGlide.SetActive(false); _ammoGlide.SetActive(false);
} }
void NormalFlight()
{
_animator.Play("glide");
ShowNormalAmmo();
}
void Shoot() void Shoot()
{ {
if (Ammo <= 0) if (Ammo <= 0)
@ -256,22 +265,41 @@ public class DragonMovement : MonoBehaviour
_flapTime -= Time.deltaTime; _flapTime -= Time.deltaTime;
_stunTime -= Time.deltaTime; _stunTime -= Time.deltaTime;
if (Input.GetKey(FlapKey))
{
_buttonHoldTime += Time.deltaTime;
}
else
{
_buttonHoldTime = 0f;
}
const float SPEED = .4f; const float SPEED = .4f;
float horizontalSpeed = SPEED; float horizontalSpeed = SPEED;
float verticalSpeed = 0f; float verticalSpeed = 0f;
if (_flapTime < - GLIDE_TIME) if (_buttonHoldTime >= DIVE_TIME)
{ {
_ammoNormal.SetActive(false); if (_isInDive == false)
_ammoGlide.SetActive(true); {
_animator.Play("speedup"); _isInDive = true;
horizontalSpeed += (_flapTime + GLIDE_TIME) * -2f; _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 else
{ {
// if (_isInDive)
{
NormalFlight();
_isInDive = false;
}
} }
@ -312,7 +340,7 @@ public class DragonMovement : MonoBehaviour
void UpdateGhosts() void UpdateGhosts()
{ {
if (_flapTime >= - GLIDE_TIME) if (_isInDive == false)
{ {
foreach (GameObject ghost in _ghosts) foreach (GameObject ghost in _ghosts)
{ {

Loading…
Cancel
Save