IEnumerator CloseOverlayAnim()
    {
        activePowerBook.CloseBook();
        yield return(new WaitUntil(() => activePowerBook.GetBookState() == PBook.BookState.CLOSED));

        activePowerBook.transform.position = activePowerBookOriginalPos;
        activePowerBook.transform.rotation = activePowerBookOriginalRot;
        SetLayer(activePowerBook.gameObject, activePowerBookOriginalLayer);
        overlayCam.gameObject.SetActive(false);
        bookIsOpen = false;
        foreach (GameObject go in disabledGameObjectsWhileReading)
        {
            go.SetActive(true);
        }
        yield return(true);
    }
    void Update()
    {
        if (openCloseKey != KeyCode.None && Input.GetKeyDown(openCloseKey))
        {
            if (pBook.GetBookState() == PBook.BookState.CLOSED)
            {
                pBook.OpenBook();
            }
            if (pBook.GetBookState() == PBook.BookState.OPEN)
            {
                pBook.CloseBook();
            }
        }

        if (nextPageKey != KeyCode.None && Input.GetKeyDown(nextPageKey))
        {
            pBook.NextPage();
        }

        if (prevPageKey != KeyCode.None && Input.GetKeyDown(prevPageKey))
        {
            pBook.PrevPage();
        }

        if (gotoLastPageKey != KeyCode.None && Input.GetKeyDown(gotoLastPageKey))
        {
            pBook.GoToLastPage(gotoSpeed);
        }

        if (gotoFirstPageKey != KeyCode.None && Input.GetKeyDown(gotoFirstPageKey))
        {
            pBook.GoToFirstPage(gotoSpeed);
        }

        if (jumpToLastPageKey != KeyCode.None && Input.GetKeyDown(jumpToLastPageKey))
        {
            pBook.JumpToLastPage(playSoundOnJump);
        }

        if (gotoFirstPageKey != KeyCode.None && Input.GetKeyDown(jumpToFirstPageKey))
        {
            pBook.JumpToFirstPage(playSoundOnJump);
        }
    }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        pointer.color = Color.white;
        if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
        {
            if ((hit.transform.parent != null && hit.transform.parent.GetComponent <PBook> () != null) || (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null))
            {
                pointer.color = Color.red;
            }
        }

        if (Input.GetKeyDown(openCloseBookKey) && activePowerBook == null)
        {
            if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent != null && hit.transform.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.CLOSED)
                    {
                        activePowerBook.OpenBook();
                    }
                    activePowerBook = null;
                }
            }

            if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                    {
                        activePowerBook.CloseBook();
                    }
                    activePowerBook = null;
                }
            }
        }

        if (Input.GetKeyDown(prevPageKey) && activePowerBook == null)
        {
            if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                    {
                        activePowerBook.PrevPage();
                    }
                    activePowerBook = null;
                }
            }
        }

        if (Input.GetKeyDown(nextPageKey) && activePowerBook == null)
        {
            if (Physics.Raycast(camTr.position + camTr.forward * raycastStartDistance, camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                    {
                        activePowerBook.NextPage();
                    }
                    activePowerBook = null;
                }
            }
        }
    }
 public void CloseBook()
 {
     pBook.CloseBook();
 }