This repository contains instructions and sample scripts to set up an AR-VR scene with virtual button control, using Vuforia and Unity. Demo video is available on YouTube. Image target base obtained from Wikimedia Commons. Image target marker obtained from this blog. Steps inferred from Vuforia Unity samples.
- Unity Game Engine - Unity 2018.2.4f1 Personal (64bit)Unity 2018.2.4f1 Personal (64bit)
- Vuforia (included in Unity) - version 7.2.23
- Login and setup a new License Key.
- Set up a new database and upload your image target (Image_target.png).
- Download the image target as a Unity package.
- Open a new project.
- In File > Build Settings, select Android and hit Switch Platform.
- In the Hierarchy, delete the Main Camera.
- Change the following Player Settings, in Edit > Project Settings > Player:
- Under XR Settings, check Virtual Reality Supported, and add the Vuforia and Cardboard SDKs.
- Under Other Settings, Identification:
- Set package name (eg: com.yourname.ARVRControlDemo)
- Set suitable Minimum API Level (tested with 23).
- Add an ARCamera to the Hierarchy using GameObject > Vuforia > ARCamera. This will prompt the import of all necessary Vuforia components.
- In Window > Vuforia Configuration
- Paste App License Key (from developer portal).
- Under Digital Eyewear
- Set Device Type to Phone + Viewer.
- Set Viewer Config to Vuforia.
- Set Viewer Type to Generic Cardboard (Vuforia).
- Import the downloaded image target Unity package using Assets > Import Package > Custom Package.
- Add an ImageTarget to the Hierarchy using GameObject > Vuforia > Camera Image > Camera Image Target.
- Set up the ImageTarget's "Image Target Behaviour (Script)" fields in the Inspector as follows:
- Set Type to Predefined.
- Set Database to the imported target package.
- Set Image Target to the target image in the imported package.
- In the Hierarchy, as a child of the ImageTarget, create a sphere to act as the planet.
- Create an empty game object child to the planet sphere, called CenterofGravity.
- Create a sphere to act as the satellite, as the child of CenterofGravity.
- Under the Assets folder, create a Scripts folder and place both povided C# scripts in it.
- To CenterofGravity, attach the SatelliteRotation.cs script (drag and drop).
- In the ImageTarget's Inspector fields, under Image Target Behaviour (Script)'s Advanced tab, choose Add Virtual Button twice.
- In the first VirtualButton's Inspector fields, under Virtual Button Behaviour (Script):
- Set Name to increaseButton
- Set Sensitivity Setting to HIGH.
- In the second VirtualButton's Inspector fields, under Virtual Button Behaviour (Script):
- Set Name to decreaseButton
- Set Sensitivity Setting to HIGH.
- In the Scene View, move the increaseButton to one of the markers on the right side, and move the decreaseButton to the other.
- Attach the VirtualButtonControlScript.cs script to the ImageTarget (drag and drop).
- Build and Run.