// Use this for initialization
    void Start()
    {
        // NOTICE : DOM

        originalPosition = new Vector3(0,0,-3);
        originalRotation = this.transform.rotation;

        touchController = GameObject.FindGameObjectWithTag("MainObject").GetComponent<TouchController>();
        foldCollide = GameObject.Find("Collision").GetComponent<FoldCollision>();
        foldReference = GameObject.Find("backsidepivot").GetComponent<Fold>();
        fingerList = new List<Vector2>();

        prefab = this.transform;

        zLayerTmp = GVariables.zCoverLayer;

        reference3 = this.transform.FindChild("coverup").gameObject;
        script = gameObject.GetComponent<ChangeMeshScript>();

        prevMouseState = false;
        currMouseState = false;
        firstTouch = false;
        isFolded = false;
    }
    // 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
    }
    // Use this for initialization
    void Start()
    {
        originalRotation = this.transform.rotation;
        //originalPosition = new Vector3(0,0,-1);
        originalPosition = this.transform.position;
        touchController = GameObject.FindGameObjectWithTag("MainObject").GetComponent<TouchController>();

        fingerList = new List<Vector2>();
        tearPoints = new List<Vector3>();

        //	stop = 0;

        prefab = this.transform;

        zLayerTmp = GVariables.zFoldLayer;

        backsideReference = this.transform.FindChild("backside").gameObject;
        foldCollide = GameObject.Find("Collision").GetComponent<FoldCollision>();
        backsideCollisionReference = GameObject.FindGameObjectsWithTag("FoldPlatform");
        cameraReference = GameObject.Find("Main Camera");

        script = gameObject.GetComponent<ChangeMeshScript>();

        prevMousestate = false;
        currMouseState = false;
        firstTouch = false;
        isFolded = false;
    }