コード例 #1
0
        private void HandleMystRemoval(Myst myst)
        {
            // Now the ring has been removed, unsubscribe from the event.
            myst.OnMystRemovalDistance -= HandleMystRemoval;


            // Remove the ring from it's collection.
            m_Mysts.Remove(myst);

            // Return the ring to its object pool.
            m_MystObjectPool.ReturnGameObjectToPool(myst.gameObject);
        }
コード例 #2
0
        private void HandleMystHit(Myst myst)
        {
            // Remove the pearl when it's hit.
            HandleMystRemoval(myst);

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

            explosion.transform.position = myst.transform.position;

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

            mystExplosion.Restart();

            // Subscribe to the asteroid explosion's event.
            mystExplosion.OnExplosionEnded += HandleMystExplosionEnded;
        }
コード例 #3
0
        private void SpawnMyst()
        {
            // Get an asteroid from the object pool.
            GameObject mystGameObject = m_MystObjectPool.GetGameObjectFromPool();

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

            mystGameObject.transform.position = mystPosition;

            // Get the asteroid component and add it to the collection.
            Myst myst = mystGameObject.GetComponent <Myst>();

            m_Mysts.Add(myst);

            // Subscribe to the asteroids events.
            myst.OnMystRemovalDistance += HandleMystRemoval;
            myst.OnMystHit             += HandleMystHit;
        }
コード例 #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);

            }
        }