void SetupVive2Controllers() { if (null == steamVRPlayArea) { steamVRPlayArea = FindObjectOfType <SteamVR_PlayArea>(); } if (null != steamVRPlayArea) { foreach (SteamVR_Behaviour_Pose pose in steamVRPlayArea.GetComponentsInChildren <SteamVR_Behaviour_Pose>(true)) { if (pose.inputSource == SteamVR_Input_Sources.RightHand) { controllerRight = pose.transform; } else if (pose.inputSource == SteamVR_Input_Sources.LeftHand) { controllerLeft = pose.transform; } } centerEye = steamVRPlayArea.GetComponentInChildren <Camera>(true).transform; } else { Debug.LogError("Please import SteamVR Plugin and put [CameraRig] prefab into your scene"); } }
private Vector3 RandomSpawnPosition() { Vector3 HeadsetPos = playArea.GetComponentInChildren <Camera>().transform.position; HeadsetPos = HeadsetPos == null ? Vector3.zero : HeadsetPos; //generate random position that is at least minDist away from player head (projected) Vector2 HeadsetPosProj = new Vector2(HeadsetPos.x, HeadsetPos.z); Vector2 RandomSpawnPosProj; float closestOtherLogDistance; do { do { RandomSpawnPosProj = new Vector2(Random.Range(-playAreaDimensions.x / 2, playAreaDimensions.x / 2), Random.Range(-playAreaDimensions.y / 2, playAreaDimensions.y / 2)); closestOtherLogDistance = int.MaxValue; foreach (GameObject log in GameObject.FindGameObjectsWithTag("Log")) { float tempDist = (new Vector2(log.transform.position.x, log.transform.position.z) - RandomSpawnPosProj).magnitude; if (tempDist < closestOtherLogDistance) { closestOtherLogDistance = tempDist; } } } while (closestOtherLogDistance < 0.3); } while ((HeadsetPosProj - RandomSpawnPosProj).magnitude < minSpawnDistance); return(new Vector3(RandomSpawnPosProj.x, 0, RandomSpawnPosProj.y)); }