// Use this for initialization.
    public void Start()
    {
        // Ensures all necessary scripts are added for the MainObject
        gameStateManagerRef = gameObject.GetComponent<GameStateManager>();
        gameStateManagerRef.EnsureCoreScriptsAdded();
        gameStateManagerRef.EnsureScriptAdded("MainMenu");

        if(gameStateManagerRef.gameStartedFromUI){
            activeScreen = gameObject.GetComponent("MainMenu") as MainMenu;
            currentScreenArea = ScreenAreas.MainMenu;
        }
        else{
            // This will not be the active screen, but active screen needs to be initialized.
            activeScreen = gameObject.GetComponent("MainMenu") as MainMenu;
            activeScreen.enabled = false;
            currentScreenArea = ScreenAreas.InGame;
        }

        screenOrientation = ScreenOrientation.Landscape;
        deviceOrientation = DeviceOrientation.LandscapeLeft;

        if(Application.platform.Equals(RuntimePlatform.Android)){
            #if UNITY_ANDROID
            using(AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"),
                    metricsClass = new AndroidJavaClass("android.util.DisplayMetrics")){
                using(AndroidJavaObject metricsInstance = new AndroidJavaObject("android.util.DisplayMetrics"),
                        activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"),
                        windowManagerInstance = activityInstance.Call<AndroidJavaObject>("getWindowManager"),
                        displayInstance = windowManagerInstance.Call<AndroidJavaObject>("getDefaultDisplay")){
                    displayInstance.Call("getMetrics", metricsInstance);
                    screenResolution.y = metricsInstance.Get<int>("heightPixels");
                    screenResolution.x = metricsInstance.Get<int>("widthPixels");
                    screenSize.x = Screen.width;
                    screenSize.y = Screen.height;
                    Screen.SetResolution((int)screenResolution.x, (int)screenResolution.y, true);
                    deviceOrientation = Input.deviceOrientation;
                }
            }
            #endif
        }
        else{
            // Overall screen resolution must be set initially to screen size for UI, then set to screen resolution while in game.
            screenSize = new Vector2(Screen.width, Screen.height);
            screenResolution = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);

            if(gameStateManagerRef.inUI){
                Screen.SetResolution((int)screenSize.x, (int)screenSize.y, gameStateManagerRef.fullScreen);
            }

            // Developer started in a level.
            else{
                Screen.SetResolution((int)screenResolution.x, (int)screenResolution.y, gameStateManagerRef.fullScreen);
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        #region initialization
        // NOTICE : DOM
        // the following is now needed
        // due to the prefab of 'MainObject'
        GameObject mainObject = GameObject.FindGameObjectsWithTag("MainObject")[0];

        if (GameObject.FindGameObjectsWithTag("MainObject").Length > 1)
        {
            GameObject[] mainObjectList = GameObject.FindGameObjectsWithTag("MainObject");
            for (int i = 0; i < mainObjectList.Length; ++i)
            {
                if (mainObjectList[i].GetComponent<GameStateManager>().objectSaved)
                    mainObject = mainObjectList[i];
            }
        }

        // Ensures all necessary scripts are added for the MainObject
        gameStateManagerRef = mainObject.GetComponent<GameStateManager>();
        gameStateManagerRef.EnsureCoreScriptsAdded();
        gameStateManagerRef.EnsureScriptAdded("TouchController");
        soundManagerRef = mainObject.GetComponent<SoundManager>();
        screenManagerRef = mainObject.GetComponent<ScreenManager>();

        #region initialize references

        backsidePivotReference = GameObject.Find("backsidepivot");
        coverupPivotReference = GameObject.Find ("coveruppivot");
        tornBacksidePieceReference = GameObject.Find ("tornBacksidePiece");
        //sets the reference of the touchcontroller to the touchcontroller script.
        touchController = mainObject.GetComponent<TouchController>();
        //sets the reference of the backsidesideReference to the backside or "fold"
        backsideReference = backsidePivotReference.transform.FindChild("backside").gameObject;

        backSideInitialColor = backsideReference.GetComponent<MeshRenderer>().material.color;

        //sets the reference of the backsideCollisionReference to the platforms on the back of the paper.
        backsideCollisionReference = GameObject.FindGameObjectsWithTag("FoldPlatform");
        //sets the camera reference to the main camera
        cameraReference = GameObject.Find("Main Camera");
        //sets the player reference to the player
        playerReference = GameObject.Find("Player_Prefab");
        //sets the backgroundTransform to the transform of the background paper.
        origBackground = GameObject.FindGameObjectWithTag("background");
        backgroundTransform = origBackground.transform;
        //sets backgroundBounds to the bounds of the background paper
        backgroundBounds = backgroundTransform.GetComponent<MeshFilter>().mesh.bounds;
        //sets changeMeshScript to the ChangeMeshScript which removes and restores triangles.
        changeMeshScript = this.GetComponent<ChangeMeshScript>();
        tearReference = GameObject.Find("Tear_Manager").GetComponent<TearManager>();
        coverupReference = coverupPivotReference.transform.FindChild("coverup").gameObject;
        tearPaperMesh = GameObject.Find("backside").GetComponent<MeshFilter>().mesh;
        unfoldCollisionReference = GameObject.Find("Player_Prefab").GetComponent<UnfoldCollision>();
        shadowReference = GameObject.Find("shadow");
        rayTraceBlockRef = GameObject.Find("rayTraceBlocker");
        paperBorderInsideRef = GameObject.Find("paper_border_inside");
        paperBorderOutsideRef = GameObject.Find("paper_border_outside");
        worldCollisionRef = mainObject.GetComponent<WorldCollision>();
        backsideTriangles = tearPaperMesh.triangles;
        #endregion

        //sets original position and rotation to its starting position and rotation
        foldOriginalRotation = backsidePivotReference.transform.rotation;
        foldOriginalPosition = backsidePivotReference.transform.position;

        //sets starting position coverup's starting position
        coverupStartingPosition = coverupPivotReference.transform.position;
        //sets coverup's original position to the vector required for the tranforms to work properly
        coverupOriginalPosition = new Vector3(0,0,-3);
        //sets coverup's original rotation to its starting rotation
        coverupOriginalRotation = coverupPivotReference.transform.rotation;

        coverupPrefab = coverupPivotReference.transform;
        foldPrefab = backsidePivotReference.transform;

        //initializes variables to defaults.
        fingerList = new List<Vector2>();
        backgroundObjMax = new Vector2();
        backgroundObjMin = new Vector2();
        posModifier = new Vector3();
        posModLastValid = new Vector3();
        unfoldPosModifier = new Vector3();
        foldTmpZLayer = GVariables.zFoldLayer - 1;
        coverupTmpZLayer = GVariables.zCoverLayer -1;
        prevMousestate = false;
        currMouseState = false;
        firstTouch = false;
        isFolded = false;
        overPlayer = false;
        needsToUnfold = false;
        isOffPaper = true;
        backsideIsInstantiated = false;
        currentlyFolding = false;
        missingTriangles = new List<Vector3>();
        //changeMeshScript.GrabUpdatedPlatforms("FoldPlatform");
        deletedTri = new int[0];
        startingQuadrant = Quadrant.NONE;
        currentQuadrant = Quadrant.NONE;
        foldEdge = Edge.BuildManifoldEdges(backsideReference.GetComponent<MeshFilter>().mesh);
        guiEnable = false;
        blah = false;

        foldInput = false;
        prevFoldInput = false;
        #endregion
    }