Example #1
0
    void Awake()
    {
        var currentInstance = _instance != null ? _instance : this;

        var inMenu = SceneManager.GetActiveScene().name == "menu";

        if (currentInstance != this)
        {
            GameManager.Instance.Camera = Camera;
            Camera.transform.parent     = GameManager.Instance.transform;
        }

        currentInstance.AllowTimeRewind = AllowTimeRewind;
        currentInstance.RewindCount     = RewindCount;

        currentInstance.CollectiblesLeft = 0;

        // Create new UI
        if (!inMenu && DrawGameUI)
        {
            var ui = Instantiate(GameUI);
            currentInstance.GameUIController = ui.GetComponent <GameUIController>();
        }

        // Setup singleton
        if (_instance != null)
        {
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(gameObject);
        _instance = this;

        // Self references
        TimeManager = GetComponent <TimeManager>();

        var fadeUI = Instantiate(FadeUI);

        fadeUI.transform.parent = transform;
        _fadeUIController       = fadeUI.GetComponent <FadeUIController>();
        _fadeUIController.SetFade(0f);

        _carHistory = new List <CarController>();

        // Start the level

        ResetState();
    }
Example #2
0
    void Awake()
    {
        // Update scene name for reloading purposes
        if (_instance != null)
        {
            _instance.CurrentScene = SceneManager.GetActiveScene().name;
        }
        else
        {
            CurrentScene = SceneManager.GetActiveScene().name;
        }

        // Setup singleton
        if (_instance != null)
        {
            Destroy(gameObject);
            return;
        }

        // Get sensitivity settings
        var prefSensX = PlayerPrefs.GetFloat("SensitivityX");
        var prefSensY = PlayerPrefs.GetFloat("SensitivityY");

        SensitivityX = prefSensX > 0f ? prefSensX : 1f;
        SensitivityY = prefSensY > 0f ? prefSensY : 1f;

        _initialFixedDeltaTime = Time.fixedDeltaTime;

        DontDestroyOnLoad(gameObject);
        _instance = this;

        // Create UIs
        var crosshairUI = Instantiate(CrosshairUI);

        crosshairUI.transform.parent = transform;

        var fadeUI = Instantiate(FadeUI);

        fadeUI.transform.parent = transform;
        _fadeUIController       = fadeUI.GetComponent <FadeUIController>();
        _fadeUIController.SetFade(0f);
    }
Example #3
0
    // Use this for initialization;
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        var fadeUI = Instantiate(FadeUI);

        fadeUI.transform.parent = transform;
        _fadeUIController       = fadeUI.GetComponent <FadeUIController>();
        _fadeUIController.SetFade(0f);

        Spawners = new List <Spawner>();

        CurrentLevel = SceneManager.GetActiveScene().name;
        GameState    = GameState.Begin;
    }