private void FireIfNeeded() { if (_fireRate <= 0f) { _fireRate = settings.projectileSpeed; var proj = PoolManager.Instance.ReuseObject(_projectile, transform.position, transform.rotation); var projectileCollision = proj.GetComponentInChildren <ProjectileCollisionBehaviour> (); projectileCollision.aoeRadius = settings.aoeRadius; projectileCollision.damage = settings.damage; projectileCollision.crashSound = settings.explodeSound; PlayerAudioBehaviour.PlaySound(settings.launchSound, transform.position); var target = _crossHair.transform.position; target.x += UnityEngine.Random.Range(-0.5f, 0.5f); target.z += UnityEngine.Random.Range(-0.5f, 0.5f); float shotHeight = target.magnitude * settings.multiplier; proj.GetComponent <Rigidbody> ().velocity = PhysicsHelpers.velocityForBasketBallThrow(transform.position, target, shotHeight); } _timeChanneled += Time.deltaTime; weaponStatusImage.fillAmount = _timeChanneled / settings.channelTime; weaponStatusImage.color = Color.Lerp(Color.white, Color.red, _timeChanneled / settings.channelTime); if (weaponStatusImage.fillAmount >= 1f) { _state = EMachineGunState.reloading; _timeChanneled = 0f; } _fireRate -= Time.deltaTime; }
protected override void HandleShot() { if (_state == EMachineGunState.reloading) { return; } _state = EMachineGunState.fire; weaponStatusImage.enabled = true; }
private void Reload() { _timeChanneled += Time.deltaTime; weaponStatusImage.fillAmount = _timeChanneled / settings.channelTime; weaponStatusImage.color = Color.Lerp(Color.white, Color.green, _timeChanneled / settings.channelTime); if (weaponStatusImage.fillAmount >= 1f) { _isReloading = false; _state = EMachineGunState.idle; weaponStatusImage.fillAmount = 0f; _timeChanneled = 0f; weaponStatusImage.enabled = false; } }
protected override void HandleShotRelease() { if (_state == EMachineGunState.reloading) { return; } if (weaponStatusImage.fillAmount < 1f) { _state = EMachineGunState.idle; } _isReloading = true; weaponStatusImage.fillAmount = 0f; weaponStatusImage.color = Color.white; _timeChanneled = 0f; }
protected override void OnEnable() { base.OnEnable(); _state = EMachineGunState.idle; }