Example #1
0
    public void InitializeAsteroid()
    {
        GameObject asteroid = pool.Get();

        asteroid.transform.position = new Vector3(spawnPointX, RandomYPosition());
        asteroid.transform.parent   = transform;

        MovingComponent moving = asteroid.GetComponent <MovingComponent>();

        moving.Initialize(RandomSpeed(), new LeftInputAdapter());
        moving.StartCoroutine(WaitForDestruction(asteroid));

        IAsteroidCollider asteroidCollider = asteroid.GetComponent <IAsteroidCollider>();

        asteroidCollider.SetCollisionCallBack(ReturnToPool);
    }
    private void Awake()
    {
        IPrefabPool asteroidPool = new PrefabPool(asteroidPoolsize, asteroidPrefab);

        asteroidCreator.Initialize(asteroidsSpeedMin, asteroidsSpeedMax,
                                   asteroidSpawnPointX, asteroidSpawnPointY, asteroidSpawnDeley, asteroidPool);


        for (int i = 0; i < ship.Count; i++)
        {
            IGameEnding gameEnding = new GameEnding(ship[i], this,
                                                    gameEndingObject, gameEndingDelay);

            LifeManager lifeManager = gameObject.AddComponent <LifeManager>();
            lifeManager.Initialize(lifeBar, shipMaxLife, ship[i], gameEnding);

            MovingComponent movingComponent = ship[i].GetComponent <MovingComponent>();
            movingComponent.Initialize(shipSpeed, new InputAdapter());
            movingComponent.GetComponent <ShipCollisionDetector>().Initialize(lifeManager.DealDamage);
        }
    }