private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; m_CurrentlySelectedObject = hit.transform.gameObject; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; m_CurrentlySelectedObject = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
/*void OnGUI() * { * GUI.Label(new Rect(10,10,500,20), "Screen: " + Screen.width + "x" + Screen.height); * GUI.Label(new Rect(10,30,500,20), "Mouse: " + Input.mousePosition.ToString("F3")); * }*/ private void MouseRaycast() { // Create a ray that points forwards from the camera. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; Vector3 worldStartPoint = Vector3.zero; Vector3 worldEndPoint = Vector3.zero; if (m_LineRenderer != null) { m_LineRenderer.enabled = ControllerIsConnected && ShowLineRenderer; } if (ControllerIsConnected && m_TrackingSpace != null) { Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * 500.0f); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Create new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); } // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object if (interactible) { worldEndPoint = hit.point; } m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(ray.origin, ray.direction); } } if (ControllerIsConnected && m_LineRenderer != null) { m_LineRenderer.SetPosition(0, worldStartPoint); m_LineRenderer.SetPosition(1, worldEndPoint); } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Modified Scripts (Inserting laser into the controller) Vector3 worldStartPoint = Vector3.zero; Vector3 worldEndPoint = Vector3.zero; if (m_LineRenderer != null) { m_LineRenderer.enabled = ControllerIsConnected && ShowLineRenderer; } if (ControllerIsConnected && m_TrackingSpace != null) { // Matrix4x4 calculates the arbitrary linear in 3D transformations // Creating a variable localToWorld and assign it to m_TrackingSpace Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); //localStartPoint variable is assigned to the controllers position //To get localEndPoint, you add the localStartPoint to the orientation and multiple the orientation the to forward function and add the distant float Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * 50.0f); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Creates a new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); } //------------------------------------------------------------------------------------------------------------------------------// // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); // Attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } // Modified to get the end point and equate it to the hit.point if (interactible) { worldEndPoint = hit.point; } m_CurrentInteractible = interactible; } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(ray.origin, ray.direction); } } // If the controller is connected and the line renderer is not nulled then it would find the start position and end position if (ControllerIsConnected && m_LineRenderer != null) { m_LineRenderer.SetPosition(0, worldStartPoint); m_LineRenderer.SetPosition(1, worldEndPoint); } }
private void CastRays(Ray ray, Vector3 worldStartPoint, Vector3 worldEndPoint) { RaycastHit[] rayhits; if (prioritezeUILayer) { //first look for UI elements rayhits = Physics.SphereCastAll(ray, m_RayRadius, m_RayLength, m_UILayers); this.hits = rayhits.Select(r => r.collider).ToArray();//.Where(g => g != null).ToArray(); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { foreach (var item in rayhits) { print(item.transform.name + "_" + item.distance); } print("_______________________"); } #endif // Do the raycast forwards to see if we hit an interactive item if (hits.Length > 0) { int indexOfChosenCollider = ProcessCollisionHits(hits, worldStartPoint); worldEndPoint = rayhits[indexOfChosenCollider].point == Vector3.zero ? worldStartPoint : rayhits[indexOfChosenCollider].point; RenderLine(worldStartPoint, worldEndPoint); if (m_Reticle) { m_Reticle.SetPosition(worldEndPoint); } return; } } //if there is no hit, then look for other colliders rayhits = Physics.SphereCastAll(ray, m_RayRadius, m_RayLength, ~m_ExclusionLayers); this.hits = rayhits.Select(r => r.collider).ToArray();//.Where(g => g != null).ToArray(); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { foreach (var item in hits) { print(item.transform.name); } print("_______________________"); } #endif // Do the raycast forwards to see if we hit an interactive item if (hits.Length > 0) { int indexOfChosenCollider = ProcessCollisionHits(hits, worldStartPoint); worldEndPoint = rayhits[indexOfChosenCollider].point == Vector3.zero ? worldStartPoint : rayhits[indexOfChosenCollider].point; } else { NoHits(); } RenderLine(worldStartPoint, worldEndPoint); if (m_Reticle) { m_Reticle.SetPosition(worldEndPoint); } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; RaycastHit [] hits; VRInteractiveItem cInteractable = null; int hitIndex = -1; hits = Physics.RaycastAll(ray); foreach (RaycastHit hitDash in hits) { hitIndex++; VRInteractiveItem interactible = hitDash.collider.GetComponent <VRInteractiveItem>(); if (interactible != null) { cInteractable = interactible; if (cInteractable.tag.Contains("Button") || cInteractable.tag.Contains("Inner")) { break; } } } // Do the raycast forweards to see if we hit an interactive item if (cInteractable != null) { VRInteractiveItem interactible = cInteractable; m_CurrentInteractible = interactible; //Debug.Log ("GFX: VREyeRaycaster:" + interactible.transform.name); float timerDuation = 4.0f; float peakFactor = 0.25f; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { //Debug.Log ("VREyeRaycaster:" + interactible.transform.name); if (interactible != null && interactible.transform.tag.Contains("Button")) { m_LastInteractible = interactible; if (interactible.tag.Contains("ButtonWord")) { StartCoroutine(FillCircle(interactible, timerDuation * peakFactor)); } else { StartCoroutine(FillCircle(interactible, timerDuation)); } } else { ResetGazer(); interactible.Over(); } } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hits[hitIndex]); } if (OnRaycasthit != null) { OnRaycasthit(hits[hitIndex]); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; ResetGazer(); // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, directionObject.position * m_DebugRayLength, Color.blue); } //Debug.Log(m_CurrentInteractible); // Create a ray that points forwards from the camera. // Ray ray = new Ray(m_Camera.position, m_Camera.forward); Ray ray = new Ray(m_Camera.position, directionObject.position * m_DebugRayLength); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object if (!m_DragingFlag) { m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.setAutoClickTime(autoClickTime); interactible.Over(); m_Reticle.fillInTime(autoClickTime); } } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. Vector3 moveVector = (Vector3.right * Input.GetAxis("Horizontal") + Vector3.up * Input.GetAxis("Vertical")); Vector3 rectPosition = m_Camera.forward * 5f; if (m_Reticle) { m_Reticle.SetPosition(directionObject.position); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; if (hit.collider.gameObject.name == "Social") { hit_object = 1; Debug.Log("Social_Click"); } else if (hit.collider.gameObject.name == "Dongsan") { hit_object = 2; Debug.Log("Dongsan_Click"); } else if (hit.collider.gameObject.name == "play") { hit_object = 3; Debug.Log("play"); } else { hit_object = 0; } // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); m_VrInput.Input_lay = true; } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { //layTime += Time.deltaTime; m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; hit_object = 0; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
/// <summary> /// Function will emit a raycast from the camera or controller. It will set <c>m_Target</c> to the current object being raycast on. /// Inside this function is also where the events are triggered and objects are interacted with (held/thrown/clicked on). /// </summary> private void Raycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; Vector3 worldStartPoint = Vector3.zero; Vector3 worldEndPoint = Vector3.zero; // If the controller is connected and we are past Scene 1, emit the raycast from the controller instead of the camera if (ControllerIsConnected && m_TrackingSpace != null && IntroSessionManager.s_Instance.GetCurrentScene() > 1) { if (!m_ControllerModel.activeSelf) { m_ControllerModel.SetActive(true); } m_ControllerModel.SetActive(true); Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * 500.0f); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Create new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); } // Do the raycast forwards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { m_Target = hit.collider.gameObject; // the target hit by the raycast m_OffsetVector = m_Target.transform.position - OVRInput.GetLocalControllerPosition(Controller); // Check if the reticle is in an interacting state if (m_CurrentReticleState == ReticleState.InteractingState && !m_HoldingObject) { m_ReticleStateTimer += Time.deltaTime; if (m_ReticleStateTimer >= 0.5f) { // Timer is finished, revert back to default IntroSessionManager.s_Instance.ReticleSetDefaultState(); m_CurrentReticleState = ReticleState.DefaultState; m_ReticleStateTimer = 0; } } // check to see if the raycast is hitting anything we can interact with and was not already aiming at one if (m_Target.tag.Contains("_Interactable_")) { // Target is interactable if (!m_OverrideDefaultReticleControls) { if (m_CurrentReticleState == ReticleState.DefaultState) { // The reticle is in its default state on the current frame // so put the reticle in a hover state. IntroSessionManager.s_Instance.ReticleSetHoverState(); m_CurrentReticleState = ReticleState.HoverState; } } // Check in here for trigger being pulled if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger)) { // Add code here to check if user clicks the trigger while targeting an object IntroSessionManager.s_Instance.ReticleSetInteracting(); // Set the reticle to its interacting state m_CurrentReticleState = ReticleState.InteractingState; //if (m_Target.tag.Contains("_EnterTagOnObjectHere_")) if (m_Target.tag.Contains("_Stage3Button_")) { // User clicked on the button AudioSource buttonSound = m_Target.GetComponent <AudioSource>(); if (buttonSound != null) { buttonSound.Play(); } // Notify any subscribers that the button has been clicked. if (e_ButtonClicked != null) { e_ButtonClicked(); } } // End checking for Stage3Button } // End checking when user pulled trigger } else { // The target is not interactable if (m_CurrentReticleState == ReticleState.HoverState && !m_OverrideDefaultReticleControls) { // On this frame the user is not looking targeting/interacting with an interactable object and the user was on the last frame // Set the reticle state to default IntroSessionManager.s_Instance.ReticleSetDefaultState(); m_CurrentReticleState = ReticleState.DefaultState; } } if (m_ObjectHeld) { // Currently holding an object if (OVRInput.GetDown(OVRInput.Button.DpadUp) || OVRInput.GetDown(OVRInput.Button.DpadLeft) || OVRInput.GetDown(OVRInput.Button.DpadRight)) { // User swiped, throw ball forward. This works if the user swipes up, left, or right. We found this made it easier for the user to throw the ball forward ThrowObject(1); } else if (OVRInput.GetDown(OVRInput.Button.DpadDown)) { // User swiped down, throw ball backwards (towards the user) ThrowObject(-1); } if (!OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)) { //Trigger button is released ReleaseObject(); m_ObjectReleased = true; } } else { // not currently holding an object if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)) { // User pulled the trigger in if (m_Target.tag.Contains("_PickUp_")) { // object being aimed at can be picked up if (m_ObjectReleased) { // User has released the trigger since the last time and now held the trigger down (for this frame). Pick up the object m_ObjectHeld = m_Target; GrabObject(); m_ObjectReleased = false; } } } else { // User is not pressing the trigger m_ObjectReleased = true; } } // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } } else { m_Target = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(ray.origin, ray.direction); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray; Vector3 worldStartPoint; Vector3 worldEndPoint; switch (PlatformManager.Instance.currentVRPlatform) { case VRPlataform.PC: default: worldStartPoint = m_Camera.position; worldEndPoint = worldStartPoint + (worldStartPoint * m_RayLength); ray = new Ray(m_Camera.position, m_Camera.forward); break; case VRPlataform.Oculus: Matrix4x4 localToWorld = m_TrackingSpace.localToWorldMatrix; Quaternion orientation = OVRInput.GetLocalControllerRotation(Controller); Vector3 localStartPoint = OVRInput.GetLocalControllerPosition(Controller); Vector3 localEndPoint = localStartPoint + ((orientation * Vector3.forward) * m_RayLength); worldStartPoint = localToWorld.MultiplyPoint(localStartPoint); worldEndPoint = localToWorld.MultiplyPoint(localEndPoint); // Create new ray ray = new Ray(worldStartPoint, worldEndPoint - worldStartPoint); break; } //first look for UI elements hits = Physics.RaycastAll(ray, m_RayLength, m_UILayers); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { foreach (var item in hits) { print(item.transform.name + "_" + item.distance); } print("_______________________"); } #endif // Do the raycast forwards to see if we hit an interactive item if (hits.Length > 0) { ProcessRaycastHits(hits, worldStartPoint, out worldEndPoint); RenderLine(worldStartPoint, worldEndPoint); return; } //if there is no hit, then look for other colliders hits = Physics.RaycastAll(ray, m_RayLength, ~m_ExclusionLayers); #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Space)) { foreach (var item in hits) { print(item.transform.name); } print("_______________________"); } #endif // Do the raycast forwards to see if we hit an interactive item if (hits.Length > 0) { ProcessRaycastHits(hits, worldStartPoint, out worldEndPoint); } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(ray.origin, ray.direction); } } RenderLine(worldStartPoint, worldEndPoint); }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { // Debug.Log (hit.collider.tag + "on:" + masterscript.GetComponent<MasterControls> ().on); VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (hit.collider.tag != "Finish" && hit.collider.tag != "Startcube") { masterscript.GetComponent <MasterControls> ().on = false; masterscript.GetComponent <MasterControls> ().onstartcube = false; //Debug.Log ("COLLIDER TAG IS NOT FINISH"); } if (hit.collider.tag == " startcube") { Debug.Log("startcube"); interactible.Over(); masterscript.GetComponent <MasterControls> ().onstartcube = true; } if (interactible && interactible != m_LastInteractible) { if (hit.collider.tag == "Finish") { //Debug.Log ("COLLIDER TAG IS FINISH " + "hit : " + hit.collider.name); masterscript.GetComponent <MasterControls> ().on = true; masterscript.GetComponent <MasterControls> ().currentroach = hit.collider.name; interactible.Over(); } else { } } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; masterscript.GetComponent <MasterControls> ().on = false; masterscript.GetComponent <MasterControls> ().onstartcube = false; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required //Debug.Log("EyeRaycast"); if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.red, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); // ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; /// // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { //Debug.Log("EyeRaycast Physics.Raycast we hit an interactive item"); VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; // If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { Debug.Log("interactible Over : " + interactible.name); interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } } else { //Debug.Log("EyeRaycast PhysicsHandleDownRaycast Nothing was hit, deactive the last interactive item"); // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }
private void EyeRaycast() { // Show the debug ray if required if (m_ShowDebugRay) { Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration); } // Create a ray that points forwards from the camera. Ray ray = new Ray(m_Camera.position, m_Camera.forward); RaycastHit hit; // Do the raycast forweards to see if we hit an interactive item if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers)) { VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object m_CurrentInteractible = interactible; //make the item interactable //create a point on the area in which there is an intersection between the ray and the object GameObject heat = Instantiate(heatTex[0], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; if (Input.GetKeyDown("s")) { GameObject[] heat2 = GameObject.FindGameObjectsWithTag("EYE"); for (int i = 0; i < 500000000; i++) { heat2[i].GetComponent <MeshRenderer>().material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 1.0f)); } } /* if (Input.GetKeyDown("t")) * { * GameObject[] heat2 = GameObject.FindGameObjectsWithTag("EYE"); * for (int i = 0; i < 500000000; i++) * heat2[i].GetComponent<MeshRenderer>().material.SetColor("_Color", new Color(1.0f, 0.0f, 0.0f, 0.0f)); * }*/ //If we hit an interactive item and it's not the same as the last interactive item, then call Over if (interactible && interactible != m_LastInteractible) { interactible.Over(); } // Deactive the last interactive item if (interactible != m_LastInteractible) { DeactiveLastInteractible(); } m_LastInteractible = interactible; // Something was hit, set at the hit position. if (m_Reticle) { m_Reticle.SetPosition(hit); } if (OnRaycasthit != null) { OnRaycasthit(hit); } //Debug.Log("here"); } else { // Nothing was hit, deactive the last interactive item. DeactiveLastInteractible(); m_CurrentInteractible = null; // Position the reticle at default distance. if (m_Reticle) { m_Reticle.SetPosition(); } } }