Example #1
0
    // Get the current scene
    //    public string currentLevel;
    //    public int currentLevelNum;
    //    public float moveTimer;
    // Use this for initialization
    void Start()
    {
        cacheCurrentLevelIndex();

        if (System.IO.File.Exists ("Save/currentSave"))
            System.IO.File.Delete ("Save/currentSave");

        displayMessage = false;
        displayPauseMenu = false;
        bool mattyProfile = false;
        bool liquidProfile = false;
        bool solidProfile = false;
        bool gasProfile = false;
        bool plasmaProfile = false;
        panTriggerActive = false;
        displayTime = 0f;
        one = 1f;
        messageToBeDisplayed = "";
        if (tipDisplayTime == 0f)
            tipDisplayTime = 10f;

        originalAmbientColor = RenderSettings.ambientLight;
        darknessTriggerSpots = new float [2];
        sceneCamera = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<Transform>();
        camFollow = sceneCamera.gameObject.GetComponent<CameraFollow>();

        iciclesList = new System.Collections.Generic.List<IcicleBase> ();
        GameObject[] icicleBaseArray = GameObject.FindGameObjectsWithTag ("IceCeiling");
        foreach (GameObject icicle in icicleBaseArray)
            iciclesList.Add (icicle.GetComponent<IcicleBase>());

        darkCave = false;
        darkCavesList = new System.Collections.Generic.List<DarkCave>();
        icicleBaseArray = GameObject.FindGameObjectsWithTag ("DarkCave");
        foreach (GameObject darkCaveEnterX in icicleBaseArray)
        {
            DarkCave newCave;
            Transform dcTransform = darkCaveEnterX.GetComponent<Transform>();
            Vector3 dcEnter = dcTransform.Find ("DarkCaveEnter").position;
            Vector3 dcExit = dcTransform.Find ("DarkCaveExit").position;

            newCave.Door1 = new Vector2 (dcEnter.x, dcEnter.y);
            newCave.Door2 = new Vector2 (dcExit.x, dcExit.y);
            darkCavesList.Add (newCave);
        }

        LoadTriggerMessagesFromFile ();
        GUIDimensionSetup ();

        // Creates a backup of the light intensities of all the lights in the scene.
        // This is needed since we need to lerp the light intensities to zero when player
        // enters dark caves.
        lights = GameObject.FindSceneObjectsOfType (typeof(Light)) as Light[];
        origLightIntensities = new float [lights.Length];
        for (int i = 0; i < lights.Length; i ++)
            origLightIntensities [i] = lights [i].intensity;

        // Creates a backup of the skybox assigned to the scene.
        // This is needed since we set the skybox to null as the player enters dark caves.
        origSkybox = RenderSettings.skybox;

        // Needed for dark caves. If background colour is not set to black, dark caves
        // won't be "dark" anymore.
        sceneCamera.gameObject.GetComponent<Camera>().backgroundColor = Color.black;

        // Define the GUIStyle to be used in the State Info Box at the bottom of the screen.
        stateInfoBox = new GUIStyle ();
        stateInfoBox.name = "StateInfoBox";
        stateInfoBox.alignment = TextAnchor.LowerRight;
        stateInfoBox.font = menuFont;
        stateInfoBox.normal.textColor = Color.white;

        player = GameObject.FindGameObjectWithTag ("Player").GetComponent<MainPlayerScript>();

        try
        {
            ld = GameObject.FindGameObjectWithTag ("LevelDirector").GetComponent<LevelDirector>();
        }
        catch (System.Exception e)
        {
            Debug.LogWarning ("A Level Director was not found for this level!");
        }

        try
        {
            levelStopwatch = GameObject.FindGameObjectWithTag("Stopwatch");
            stopwatch = levelStopwatch.GetComponent<Stopwatch>();

            if (PlayerPrefs.GetString(Constants.GameModeKey).Equals(Constants.GameModeSpeedRun))
            {
                stopwatch.startStopwatch();
                isSpeedRun = true;
            }

            player.setIsSpeedRun(isSpeedRun);

        }
        catch (System.NullReferenceException e)
        {
            Debug.LogWarning ("Stopwatch was not found for this level!");
        }
        catch (System.Exception e)
        {
            Debug.LogError (e.Message);
        }

        mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();

        try
        {
            subcam = GameObject.FindGameObjectWithTag("SubsectionCamera");
            subsectionCam = subcam.GetComponent<Camera>();
            //subsectionCamPos = subcam.transform;

            subsectionCam.enabled = false;
            mainCam.enabled = true;
        }
        catch (System.Exception e)
        {
            Debug.LogWarning("No subsection camera was found");
        }

        startSubsectCam = false;
    }