Example #1
0
        private void HandlePearlRemoval(Pearl pearl)
        {
            // Only one of HandleAsteroidRemoval and HandleAsteroidHit should be called so unsubscribe both.
            pearl.OnPearlRemovalDistance -= HandlePearlRemoval;
            pearl.OnPearlHit             -= HandlePearlHit;

            // Remove the asteroid from the collection.
            m_Pearls.Remove(pearl);

            // Return the asteroid to its object pool.
            m_PearlObjectPool.ReturnGameObjectToPool(pearl.gameObject);
        }
Example #2
0
        private void HandlePearlHit(Pearl pearl)
        {
            // Remove the pearl when it's hit.
            HandlePearlRemoval(pearl);

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

            explosion.transform.position = pearl.transform.position;

            // Get the pearl explosion component and restart it.
            PearlExplosion pearlExplosion = explosion.GetComponent <PearlExplosion>();

            pearlExplosion.Restart();

            // Subscribe to the asteroid explosion's event.
            pearlExplosion.OnExplosionEnded += HandlePearlExplosionEnded;
        }
Example #3
0
        private void SpawnPearl()
        {
            // Get an asteroid from the object pool.
            GameObject pearlGameObject = m_PearlObjectPool.GetGameObjectFromPool();

            // Generate a position at a distance forward from the camera within a random sphere and put the asteroid at that position.
            Vector3 pearlPosition = m_Cam.position + Vector3.forward * m_SpawnZoneDistance + Random.insideUnitSphere * m_PearlSpawnZoneRadius;

            pearlGameObject.transform.position = pearlPosition;

            if (pearlGameObject.transform.position.z - m_Cam.position.z < 100)
            {
                pearlPosition.z = m_Cam.position.z;
            }

            // Get the asteroid component and add it to the collection.
            Pearl pearl = pearlGameObject.GetComponent <Pearl>();

            m_Pearls.Add(pearl);

            // Subscribe to the asteroids events.
            pearl.OnPearlRemovalDistance += HandlePearlRemoval;
            pearl.OnPearlHit             += HandlePearlHit;
        }
Example #4
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);

            }
        }