// Update is called once per frame void FixedUpdate() { intr_Book raycastInteractable; RaycastHit HitInfo = new RaycastHit(); if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out HitInfo, 15.0f)) { //check if collider hit has book interaction script raycastInteractable = HitInfo.collider.gameObject.GetComponent <intr_Book>(); //if there is if (raycastInteractable != null) { //check if there is a rayhit if (rayHit != null) { //there is a rayhit, check if the same one is being hit, if it isn't disable the old one and enable the new one then assign the reference to the new one if (!string.Equals(rayHit.gameObject.name, raycastInteractable.gameObject.name)) { raycastInteractable.enableCanvas(); rayHit.disableCanvas(); rayHit = raycastInteractable; } } else { Debug.Log("Looking at same object"); raycastInteractable.enableCanvas(); rayHit = raycastInteractable; } } } else { if (rayHit != null) { rayHit.disableCanvas(); rayHit = null; } } }
// This function will be called by StateFrame each fixed Timestep. public override void Listen(StateFrame frame) { // We perform a cast to the required StateFrame type, to reduce "GetComponent" calls at runtime. PlayerStateFrame playerFrame = frame as PlayerStateFrame; // We peek the latest queued input from the player's input buffer. string latestInput = playerFrame.inputBuffer.PeekQueuedInput(); // If the player presses Action 1, reveal the void. if (latestInput.Equals(InputName.Action1) && !playerFrame.voidController.VoidActive && playerFrame.interactionManager.currentInteraction == null) { // 1. Manage the input. Debug.Log("Action 1 Performed. "); playerFrame.inputBuffer.PopQueuedInput(); // 2. Manage the state transition. frame.StateTransition(playerFrame.voidController.AimVoidState); } // If the player presses Action 2, repress the void. else if (latestInput.Equals(InputName.Action2) && playerFrame.voidController.VoidActive && playerFrame.interactionManager.currentInteraction == null) { Debug.Log("Action 2 Performed. "); // 1. Manage the input. playerFrame.inputBuffer.PopQueuedInput(); // 2. Manage the state transition. frame.StateTransition(playerFrame.voidController.FocusRepressState); } else if (playerFrame.interactionManager.currentInteraction is InspectableObject && !playerFrame.inspectController.IsInspecting || playerFrame.interactionManager.currentInteraction is intr_Book && !playerFrame.inspectController.IsInspecting || playerFrame.interactionManager.currentInteraction is intr_RetrainOrder && !playerFrame.inspectController.IsInspecting) { if (playerFrame.interactionManager.currentInteraction is intr_Book) { intr_Book interaction = playerFrame.interactionManager.currentInteraction as intr_Book; if (interaction.isPulled) { // 1. Manage the input. playerFrame.inputBuffer.PopQueuedInput(); // 2. Manage the state transition. frame.StateTransition(playerFrame.inspectController.InitiateInspectState); } } else { // 1. Manage the input. playerFrame.inputBuffer.PopQueuedInput(); // 2. Manage the state transition. frame.StateTransition(playerFrame.inspectController.InitiateInspectState); } } else if (playerFrame.interactionManager.currentInteraction is intr_Lock && !playerFrame.lockController.IsLock) { // 1. Manage the input. playerFrame.inputBuffer.PopQueuedInput(); // 2. Manage the state transition. frame.StateTransition(playerFrame.lockController.LockState); } // If the player presses Action 4, sprint. if (playerFrame.inputBuffer.ActionHeld(InputName.Action4) && playerFrame.interactionManager.currentInteraction == null) { Debug.Log("Action 4 Performed. "); if (!playerFrame.motor.noStamina) { playerFrame.motor.isSprinting = true; } else { playerFrame.motor.isSprinting = false; } } else { playerFrame.motor.isSprinting = false; } }