public void OnDestroy(object sender, GameObject gameObject)
        {
            switch (gameObject)
            {
            case Player g:
                Player.Fire -= AddBullet;
                _enemyController.CreateEnemy -= OnCreateEnemy;

                foreach (var enemy in _enemies)
                {
                    enemy.OnDestroy();
                }

                foreach (var bullet in _bullets)
                {
                    bullet.OnDestroy();
                }
                break;

            case Enemy g:
                EnemyDestroyed?.Invoke(this, gameObject);
                break;
            }
            gameObject.Destroy -= OnDestroy;
            _removingObjects.Add(gameObject);
        }
示例#2
0
        protected void Die()
        {
            // TODO: Do some cool explosion animations or something and then end level

            EnemyDestroyed?.Invoke(this, EventArgs.Empty);
            Destroy(this);
        }
 void DestroyEnemy()
 {
     Destroy(CurrentEnemy.obj);
     CurrentEnemy = null;
     EnemyDestroyed?.Invoke();
     GameManager.obj.OnEnemyKilled();
     PackGridManager.obj.RemoveAll(GridObject.Type.JUNK);
 }
示例#4
0
    protected void OnCollisionEnter2D(Collision2D col)
    {
        if (EnemyDestroyed != null)
        {
            EnemyDestroyed.Invoke();
        }

        Instantiate(deathParticles, transform.position, transform.rotation);
        Destroy(gameObject);
    }
示例#5
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.layer == PROJECTILE_LAYER)
     {
         Destroy(other.gameObject);
         life--;
         if (life <= 0)
         {
             EnemyDestroyed?.Invoke(this);
             Destroy(gameObject);
         }
     }
 }
示例#6
0
    protected virtual void HitByBullet(GameObject other)
    {
        Debug.Log("particle collision");

        hitsRemaining--;

        if (hitsRemaining < 1)
        {
            EnemyDestroyed?.Invoke(hitsToKill, transform.position);
            Destroy(gameObject);
        }

        //var part = other.GetComponent<ParticleSystem>();
        //int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
        //int i = 0;
        //while (i < numCollisionEvents)
        //{
        //    Debug.Log("particle collision");
        //    i++;
        //}
    }
 public static void CallEnemyDestroyed(int pointValue)
 {
     EnemyDestroyed?.Invoke(pointValue);
 }