private void HandleAsteroidRemoval(Asteroid asteroid)
        {
            // Only one of HandleAsteroidRemoval and HandleAsteroidHit should be called so unsubscribe both.
            asteroid.OnAsteroidRemovalDistance -= HandleAsteroidRemoval;
            asteroid.OnAsteroidHit -= HandleAsteroidHit;

            // Remove the asteroid from the collection.
            m_Asteroids.Remove(asteroid);

            // Return the asteroid to its object pool.
            m_AsteroidObjectPool.ReturnGameObjectToPool (asteroid.gameObject);
        }
        private void HandleAsteroidHit(Asteroid asteroid)
        {
            // Remove the asteroid when it's hit.
            HandleAsteroidRemoval (asteroid);

            // Get an explosion from the object pool and put it at the asteroids position.
            GameObject explosion = m_AsteroidExplosionObjectPool.GetGameObjectFromPool ();
            explosion.transform.position = asteroid.transform.position;

            // Get the asteroid explosion component and restart it.
            AsteroidExplosion asteroidExplosion = explosion.GetComponent<AsteroidExplosion>();
            asteroidExplosion.Restart();

            // Subscribe to the asteroid explosion's event.
            asteroidExplosion.OnExplosionEnded += HandleExplosionEnded;
        }
Exemple #3
0
        private void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.name.Contains("FlyerShark"))
            {

                Shark shark = other.gameObject.GetComponent<Shark>();

                shark.Hit();

                // The laser has hit something.
                m_Hit = true;

                dolphin.hitAudio.Play();

                // Return the laser to the object pool.
                ObjectPool.ReturnGameObjectToPool(gameObject);

            }

             if (other.gameObject.name.Contains("FlyerAsteroid"))
            {

                Asteroid asteroid = other.gameObject.GetComponent<Asteroid>();
                asteroid.Hit();

                // The laser has hit something.
                m_Hit = true;

                dolphin.hitAudio.Play();

                // Return the laser to the object pool.
                ObjectPool.ReturnGameObjectToPool(gameObject);

            }

            if (other.gameObject.name.Contains("FlyerOctopus"))
            {

                Pearl pearl = other.gameObject.GetComponent<Pearl>();
                pearl.Hit();

                dolphin.hitAudio.Play();

                // The laser has hit something.
                m_Hit = true;

                // Return the laser to the object pool.
                ObjectPool.ReturnGameObjectToPool(gameObject);

            }

            if (other.gameObject.name.Contains("FlyerUrchin"))
            {

                Myst myst = other.gameObject.GetComponent<Myst>();
                myst.Hit();

                dolphin.hitAudio.Play();

                // The laser has hit something.
                m_Hit = true;

                // Return the laser to the object pool.
                ObjectPool.ReturnGameObjectToPool(gameObject);

            }
        }