Example #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Laser")
        {
            other.gameObject.SetActive(false);
            int        explosionID = _explosionPrefab.GetExplosionID();
            GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
            if (explosion != null)
            {
                explosion.transform.position = transform.position;
                explosion.SetActive(true);
            }
            OnStartSpawning?.Invoke();
            gameObject.GetComponent <Collider2D>().enabled = false;
            Destroy(gameObject, _destroyDelay);
        }

        if (other.tag == "Omni Shot")
        {
            int        explosionID = _explosionPrefab.GetExplosionID();
            GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
            if (explosion != null)
            {
                explosion.transform.position = transform.position;
                explosion.SetActive(true);
            }
            OnStartSpawning?.Invoke();
            gameObject.GetComponent <Collider2D>().enabled = false;
            Destroy(gameObject, _destroyDelay);
        }
    }
Example #2
0
 void DamageCore(int amount = -1)
 {
     _currentReactorHealth += amount;
     if (_currentReactorHealth <= 0)
     {
         OnScored?.Invoke(_scoreValue);
         OnDestroyed?.Invoke();
         int        explosionID = _explosionPrefab.GetExplosionID();
         GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
         explosion.transform.position = transform.position;
         explosion.SetActive(true);
         gameObject.SetActive(false);
     }
 }
Example #3
0
    void OnDisable()
    {
        Enemy.OnDestroyed     -= RemoveTarget;
        Player.OnRemoveTarget -= RemoveTarget;

        if (_isReused == true)
        {
            int        explosionID = _explosionPrefab.GetExplosionID();
            GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
            if (explosion != null)
            {
                explosion.transform.position = transform.position;
                explosion.SetActive(true);
            }
            transform.position         = transform.parent.position;
            _isEnemyMissile            = false;
            _timer                     = 0;
            _target                    = null;
            _rigidBody.angularVelocity = 0;
            transform.rotation         = Quaternion.Euler(Vector3.zero);
        }
    }
Example #4
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            OnDamagePlayer?.Invoke(-_damage);
            int        explosionID = _explosionPrefab.GetExplosionID();
            GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
            if (explosion != null)
            {
                explosion.transform.position = transform.position;
                explosion.SetActive(true);
            }
            gameObject.SetActive(false);
        }

        if (other.tag == "Laser")
        {
            OnScored?.Invoke(_scoreValue);
            other.gameObject.SetActive(false);
            int        explosionID = _explosionPrefab.GetExplosionID();
            GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
            explosion.transform.position = transform.position;
            explosion.SetActive(true);
            gameObject.SetActive(false);
        }

        if (other.tag == "Omni Shot")
        {
            OnScored?.Invoke(_scoreValue);
            int        explosionID = _explosionPrefab.GetExplosionID();
            GameObject explosion   = OnGetExplosion?.Invoke(explosionID);
            explosion.transform.position = transform.position;
            explosion.SetActive(true);
            gameObject.SetActive(false);
        }
    }
Example #5
0
    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);
        }
    }