// Use this for initialization void Start() { playArea = GetComponent <SteamVR_PlayArea> (); //Teleporting Play Area teleportPlayArea = new GameObject("TeleportPlayArea"); teleportPlayArea.transform.SetParent(transform); MeshRenderer mR = teleportPlayArea.AddComponent <MeshRenderer> (); MeshFilter mF = teleportPlayArea.AddComponent <MeshFilter> (); mF.mesh = playArea.GetComponent <MeshFilter> ().sharedMesh; mR.material = playArea.GetComponent <MeshRenderer> ().sharedMaterial; SteamVR_TrackedObject[] trackedObjects = transform.GetComponentsInChildren <SteamVR_TrackedObject> (true); for (int i = 0; i < trackedObjects.Length; i++) { if (trackedObjects [i].index == SteamVR_TrackedObject.EIndex.Hmd) { hmd = trackedObjects [i].transform.parent; } } playerTeleportLocation = GameObject.Instantiate(playerTeleportLocationPrefab).transform; playerTeleportLocation.SetParent(teleportPlayArea.transform); teleportPlayArea.SetActive(false); }
void openDoor() { Vector3 playerPos = player.transform.position; Bounds bounds = playArea.GetComponent <MeshRenderer> ().bounds; float[] diffs = { playerPos [0] - bounds.min [0], playerPos [2] - bounds.min [2], bounds.max [0] + playerPos [0], bounds.max [2] + playerPos [2] }; int nMin = 0; float min = diffs [0]; for (int i = 1; i < 4; i++) { if (diffs [i] < min) { min = diffs [i]; nMin = i; } } Vector3 dir; switch (nMin) { case 0: dir = Vector3.left; break; case 1: dir = Vector3.back; break; case 2: dir = Vector3.right; break; case 3: dir = Vector3.forward; break; default: dir = Vector3.zero; break; } transform.position += Vector3.Scale(dir, bounds.size); player.transform.Rotate(0, 180, 0); playArea.transform.localScale = Vector3.Scale(playArea.transform.localScale, (nMin % 2 == 0 ? Vector3.left : Vector3.back)); }