[Virtual Reality] Realization of Unity3D+VR
For CardBoard Use Unity3D to develop VR content for glasses.
1. Create VRCamera: Use the Dive plug-in to extract the camera and related scripts from DiveUnityDemo and export them. 2. Object selection: Visual selection mode: launch a ray from the eye and select the object you see. Handle mode: Use the buttons on the Bluetooth handle to select objects. 3. Realization of visual selection mode: Visual selection: use Raycast to detect, RaycastHit returns the information of the colliding object. private RaycastHit rayHitInfo; public Transform goPoint;//is the ray emitting point, which is a point between the two cameras. if (Physics.Raycast(goPoint.position, goPoint.forward, out rayHitInfo)) {Debug.Log(“RaySelect: “+ rayHitInfo.collider.gameObject.name);} Focus: Create a new Plane and put it in the same place as Point In the local coordinate system, then adjust the transform to place it in the middle of the field of view, and select the Mesh collider. Develop animation effects for the focus: Texture loops. Set a dwell time for the visual selection: it does not mean that it is triggered when you see an object, but it is triggered by staring at an object for a certain period of time. 4. The realization of the handle mode: Check whether the handle exists: if ((Input.GetJoystickNames().Length> 0) && (!Input.GetJoystickNames()[0].Equals(“”))) {// Handle exists} void Start () {InvokeRepeating(“detect”, 0, 5);//Call the detect function every 5s to detect the handle. } Detect the handle buttons: if (Input.GetKeyDown(KeyCode.Joystick1Button0)) {//Handle key 1} else if (Input.GetKeyDown(KeyCode.Joystick1Button1)) {//Handle key 2} //and so on to set and check Handle joystick: Set the joystick by adding the axis handle in the input. There are 4 directions, and four new ones need to be set. Detect joystick: if (Input.GetAxis(“AxisName”)) {//One direction of joystick }