// Init function for launching the playercontroller in play mode.
    public void InitPlayMode()
    {
        levelRef = FindObjectOfType <MainLevel>();

        SetCameraRails();

        UIMenuRef       = levelRef.GetComponent <MenuManager>();
        spawnManagerRef = levelRef.GetComponent <SpawnManager>();
        mapManagerRef   = levelRef.GetComponent <MapEditorManager>();

        // Index 0 of the tileMap's structure Palette is the Castle Prefab.
        castleRef = spawnManagerRef.castleRef;

        levelRef.GetComponent <MainLevel>().SetGameState(MainLevel.GameState.PLACECASTLE);
        UIMenuRef.OpenMenu(UIMenuRef.placeCastleNotif);

        this.enabled = true;
    }
    // Init function for launching the playercontroller in the map editor.
    public void InitEditMode()
    {
        mat_index     = 0;
        editState     = CurrentEditMode.NO_OBJ;
        levelRef      = FindObjectOfType <MapEditorLevel>();
        mapManagerRef = levelRef.GetComponent <MapEditorManager>();
        SetCameraRails();

        this.enabled = true;
    }
        // Native Functions ******************************************************************************
        // ***********************************************************************************************

        void Awake()
        {
            levelRef      = FindObjectOfType <LevelScript>();
            mapManagerRef = levelRef.GetComponent <MapEditorManager>();
        }
    private void UpdatePlayMode()
    {
        if (levelRef.GetComponent <MainLevel>().gameState == MainLevel.GameState.PLACECASTLE)
        {
            if (Time.timeSinceLevelLoad > levelRef.GetComponent <MainLevel>().castlePromptTime)
            {
                PlaceStructure(castleRef);
            }
        }
        else // Build/Combat Phases
        {
            if (Input.GetMouseButtonDown(0))
            {
                PlayModeClickInput();
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            PauseGame();
        }
    }