Create your First VR Game using Unity, Check Our Simple Demo Code !
Currently, the most popular option for developing VR games is Unity. Google CardBoard comes as the prime choice to get started rather than spending plenty. Loads of people having smartphones can enjoy your game on a lesser expense.
The core purpose of this tutorial is to describe how to integrate Cardboard SDK with Unity.
Setup for Cardboard SDK
With this SDK and Unity, you can create virtual reality applications in Android as well as iOSthat runs in Google cardboard.
How to import and preview the demo scene SDKs Package?
Follow 3 simple steps below to import and preview the demo scene SDKs Package :
- Open Unity
- For SDK package, go to Assets -> Import Package -> Custom Package.
- For Demo Package which is a default demo game, go to Assets -> Import Package -> Custom Package.
How to build a demo ?
Follow the below steps to build a demo :
- Go to File, select Build Settings and then select Android as your platform.
- Click Player Settings. Under “Other Settings”, enter a package name into the “Bundle Identifier” field (for example, com.example.CardboardUnityDemo). Under “Resolution and Presentation”, check if the default orientation is set to “Landscape Left”.
- Click on Build and Run.
Create a game Scary Hospital
Please follow the below instruction and build your own game !
- Select prefab CameraMain from Cardboard from Assets.Then simply drag and drop into inspector.Later on, you can adjust camera position according to your viewpoint.
- Now run the project to see how your model looks in game Mode.
It will look similar to the picture shown below:
In playMode, you can move camera using Alt and moving mouse. It will help you see like how things look in vr.
2. Interact with UI
- One thing we have to consider is UI must be replicated in each eye. So we have to place in virtual space to focus.
- Create canvas and set it to worldspace.
- To accomplish this, add the GazeInputMobile script to scene Eventsystem.
3. Creating Reticle
We need a particular pointer to aim something like clicking buttons, hovering.
You can create this by Select a prefab from Cardboard, go to UI and select CardBoardReticle Script into CardBoardMain game object in inspector. Make sure its parent is MainCamera.
This prefab has attached Script named CardboardReticle which has 2 properties as:
- Reticle Segments: Number of segments making reticle circle.
- Reticle GrowthSpeed: Growth speed multiplier for the reticle when we aim into UI.
Now, you can hover on UI and can click buttons.
You can make many stuff with the help of this. Currently in my demo , if I hover on Alien for 3 seconds, it will die!
Check Our Demo Here: Download Dropbox Link
Now you can develop your own game referring the demo dropbox link given above and feel free to use it. This article would be a perfect pick to developing VR games describing an easy and trouble free way working with Google CardBoard and Unity. As always, please comment below.