Exemple #1
0
        private void HandleOpponentHit(Opponent opponent)
        {
            // Remove the opponent when it's hit.
            HandleOpponentRemoval(opponent);

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

            explosion.transform.position = opponent.transform.position;

            // Get the asteroid explosion component and restart it.
            ObstacleExplosion obstacleExplosion = explosion.GetComponent <ObstacleExplosion>();

            obstacleExplosion.Restart();

            // Subscribe to the asteroid explosion's event.
            obstacleExplosion.OnExplosionEnded += HandleOpponentExplosionEnded;
        }
Exemple #2
0
        private void SpawnOpponent()
        {
            // Get an opponent from the object pool.
            GameObject opponentGameObject = m_OpponentObjectPool.GetGameObjectFromPool();

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

            opponentGameObject.transform.position = opponentPosition;

            // Get the opponent component and add it to the collection.
            Opponent opponent = opponentGameObject.GetComponent <Opponent>();

            m_Opponents.Add(opponent);

            // Subscribe to the opponents events.
            opponent.OnOpponentRemovalDistance += HandleOpponentRemoval;
            opponent.OnOpponentHit             += HandleOpponentHit;
        }