// Fetch Raycasted Object Name. In case of exception the object is null. private static RayCastSpecimen onRaycasting() { // Get the head position and gaze direction from the Main Camera object Vector3 headPosition = GameObject.Find("Main Camera").transform.position; Vector3 gazeDirection = GameObject.Find("Main Camera").transform.forward; RayCastSpecimen raycastspecimen = new RayCastSpecimen(); string gameObjectName = ""; string parentName = ""; string folder_door_right = "RightDoor"; string folder_door_left = "LeftDoor"; RaycastHit hitInfo; try{ Physics.Raycast(headPosition, gazeDirection, out hitInfo); GameObject.Find("Ray").transform.position = hitInfo.point; parentName = hitInfo.collider.gameObject.transform.parent.name; if (parentName == folder_door_left || parentName == folder_door_right) { raycastspecimen.foldertext = hitInfo.collider.gameObject.transform.parent.transform.GetChild(3).gameObject.GetComponent <TextMesh>().text; } else { raycastspecimen.foldertext = "null"; } } catch { raycastspecimen.foldertext = "null"; } return(raycastspecimen); }
// Update is called once per frame void Update() { Quaternion gazeDirection = GameObject.Find("Main Camera").transform.localRotation; RayCastSpecimen raycastspecimen = new RayCastSpecimen(); raycastspecimen = onRaycasting(); Debug.Log(raycastspecimen.foldertext); Debug.Log(GameObject.Find("Ray").transform.position); // Back Button Event if (Input.GetMouseButton(backButton)) { if (listEntry.Count != 1 && backButtonCounter < 1) { listEntry.RemoveAt(listEntry.Count - 1); string filepath = listEntry[listEntry.Count - 1]; listEntry.RemoveAt(listEntry.Count - 1); onDestroyScene(); onCreateScene(filepath); getInitialPosition(); backButtonCounter++; } } else { if (Input.GetMouseButton(travelButton)) { // Initializing the back counter variable to launch at the right click event or back button event if (backButtonCounter != 0) { backButtonCounter = 0; } if (raycastspecimen.foldertext != "null") { if (isUsed) { onDestroyScene(); onCreateScene(listEntry[listEntry.Count - 1] + "//" + raycastspecimen.foldertext); //onCreateScene(listEntry[listEntry.Count - 1] + "\\" + raycastspecimen.foldertext); getInitialPosition(); } else { isUsed = true; } } else { if (Vector3.Distance(GameObject.Find("Ray").transform.position, GameObject.Find("Main Camera").transform.position) > 1) { Vector3 travelVector = gazeDirection * Vector3.forward * travelSpeed; travelVector.y = 0; GameObject.Find("Travel").transform.Translate(travelVector); } } } } }