Exemplo n.º 1
0
    public void PrepareAndStartGame()
    {
        StopAllCoroutines();

        mainUI.SetActive(false);
        resumePanel.SetActive(false);

        Action onGameSceneLoaded = () =>
        {
            blackScreen.SetActive(false);

            mainUI.SetActive(true);

            baseList = new List <GameObject>();

            EventManager.StartListening(Statics.Events.gameOver, OnGameOver);
            EventManager.StartListening(Statics.Events.baseFound, OnEndGame);

            player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity).GetComponent <PlayerController>();

            CameraFollow cam = Camera.main.GetComponent <CameraFollow>();
            cam.SetTarget(player.transform);

            asteroidSpawner = gameObject.GetComponent <AsteroidSpawner>();
            moduleManager   = gameObject.GetComponent <ModuleManager>();

            uiManager = gameObject.GetComponent <UIManager>();

            asteroidSpawner.Init(Camera.main);
            moduleManager.Init(Camera.main);

            if (enableAsteroids)
            {
                asteroidSpawner.StartSpawner();
            }

            uiManager.Init(player.maxHull, player.minHull, player.maxOxygen, player.minOxygen);

            moduleManager.StartSpawner();

            CreateBases();

            StartCoroutine(CheckBasesAreTooFarAway());

            Fade(false);
        };

        sceneManager.LoadGame(onGameSceneLoaded);
    }