void Init() { transform.position = Vector2.zero; _baseSpeed = _speed; _currentAmmo = _maxAmmo; _lives = _maxLives; _tripleShotDuration = _powerUpDuration; _speedBoostDuration = _powerUpDuration; _omniShotDuration = _powerUpDuration; _negativeEffectDuration = _powerUpDuration; _shieldRenderer = _shieldVisual.GetComponent <SpriteRenderer>(); _fullShieldColor = _shieldRenderer.color; _shieldVisual.SetActive(false); for (int i = 0; i < _engineFires.Length; i++) { _engineFires[i].SetActive(false); } OnUpdateLives?.Invoke(_lives); OnUpdateThuster?.Invoke(_elapsedTime, _thrusterBurnLength); OnUpdateAmmo?.Invoke(_currentAmmo, _maxAmmo); OnUpdateMissiles?.Invoke(_currentMissiles, _numberOfMissiles); }
public void ChangeLives(int amount) { if (_isShieldActive == true && amount < 0) { _currentShieldStrength--; if (_currentShieldStrength > 0) { ChangeShield(_currentShieldStrength); return; } _isShieldActive = false; _shieldVisual.SetActive(false); return; } if (amount < 0) { OnCameraShake?.Invoke(); } _lives += amount; if (_lives > _maxLives) { _lives = _maxLives; } else if (_lives < 0) { _lives = 0; } OnUpdateLives?.Invoke(_lives); if (_lives == 3) { if (_engineFires[0].activeInHierarchy == true) { _engineFires[0].SetActive(false); } if (_engineFires[1].activeInHierarchy == true) { _engineFires[1].SetActive(false); } } else if (_lives == 2) { _engineFires[0].SetActive(true); if (_engineFires[1].activeInHierarchy == true) { _engineFires[1].SetActive(false); } } else if (_lives == 1) { _engineFires[1].SetActive(true); if (_engineFires[0].activeInHierarchy == false) { _engineFires[0].SetActive(true); } } else if (_lives < 1) { int explosionID = _explosionPrefab.GetExplosionID(); GameObject explosion = OnGetExplosion?.Invoke(explosionID); explosion.transform.position = transform.position; explosion.SetActive(true); OnRemoveTarget?.Invoke(gameObject); OnDeath?.Invoke(); gameObject.SetActive(false); } }