// Update is called once per frame void Update() { if (!bookIsOpen) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, raycastDistance)) { if (hit.transform.parent != null && hit.transform.parent.GetComponent <PBook> () != null) { activePowerBook = hit.transform.parent.GetComponent <PBook> (); activePowerBookOriginalLayer = activePowerBook.gameObject.layer; SetLayer(activePowerBook.gameObject, LayerMask.NameToLayer(overlayLayer)); BoxCollider bookCollider = (BoxCollider)hit.collider; activePowerBookOriginalPos = hit.transform.position; activePowerBookOriginalRot = hit.transform.rotation; activePowerBook.transform.position = new Vector3((bookCollider.size.y / 2) - 0.005f, 0, -bookCollider.size.z / 2); activePowerBook.transform.rotation = Quaternion.Euler(perspectiveAngle, 0, 0); overlayCam.transform.position = new Vector3(0, ((bookCollider.size.z * 1.4f) - (bookCollider.size.y / 2)) - perspectiveAngle * 0.003f, -perspectiveAngle * 0.001f); overlayCam.gameObject.SetActive(true); if (autoOpenBook) { activePowerBook.OpenBook(); } bookIsOpen = true; foreach (GameObject go in disabledGameObjectsWhileReading) { go.SetActive(false); } } } } } else { if (Input.GetKey(openCloseKey)) { if (activePowerBook.GetBookState() == PBook.BookState.CLOSED) { activePowerBook.OpenBook(); } else if (activePowerBook.GetBookState() == PBook.BookState.OPEN) { CloseOverlay(); } } if (Input.GetKey(nextPageKey)) { activePowerBook.NextPage(); } if (Input.GetKey(prevPageKey)) { activePowerBook.PrevPage(); } } }
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 NextPage() { pBook.NextPage(); }