Simple HandTracking tutorial. Use hand tracking to pinch to increase the count!
Sample Repository
Run the sample
- Clone Sample Repository, Change current directory to
HandTracking. And Open with Unity. - (If you don't have NRSDK) Download NRSDK 1.8.0 from Download | Nreal
- Open
Build Setting, change Platform toAndroid - Open
Project, selectAssets>import package>Custom Packageand importNRSDKForUnityAndroid_1.8.0.unitypackage. - Check
Build Settings>Player Settingsby referring to Configure Build Settings - Press
BuildformBuild Settingspanel - Install *.apk on Android or DevKit.
Tutorial
1. Setting up the project for Nreal development
- See Quickstart for Android - NRSDK Documentation and configure the build settings.
- (If you don't have NRSDK) Download NRSDK 1.8.0 from Download | Nreal
- Open
Project, selectAssets>import package>Custom Packageand importNRSDKForUnityAndroid_1.8.0.unitypackage.
2. Setting for HandTracking to NRInput
- Select
NRInput, and changeInput Source TypetoHands - Put
NRHand_RfromAssets>NRSDK>Prefabs>HandstoNRInput>Right - Put
NRHand_LfromAssets>NRSDK>Prefabs>HandstoNRInput>Left
3. Create Material
- Open
Project, selectAssets - Create
MaterialonAssets- Change name to “TouchCubeMaterial”
- Change
Albedoto “CC0000”
4. Put Cube in the Scene
- Put
Cubein the Scene- Change name to “TouchCube”
-
Pos X: 0,Pos Y: 0,Pos Z: 8
5. Put a Canvas in the scene
- Put
CanvasfromCreate>UI - Set property on
Inspectorpanel-
Render Mode: World Space -
Pos X: 0 ,Pos Y: -0.35Pos Z: 3 -
Scale-
X: 0.005 ,Y: 0.005 ,Z: 0.005
-
-
6. Put Text in Canvas
- Put
Textas a child ofCanvaswith the name "Counter”.-
Pos X: 0,Pos Y: -30,Pos Z: 3 - Change
Textto “0” - Change
Colorto “FFCC00” - Change Font size to 30
-
7. Create C# Script in Assets
- Create
C# Scriptin the asset with the file name "HandTrack.cs". - Write the code as follows
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class HandTrack : MonoBehaviour, IPointerClickHandler
{
/// <summary>
/// Counter Text GameObject
/// </summary>
public Text targetText;
/// <summary>
/// Counter value
/// </summary>
private int counter = 0;
/// <summary>
/// HandTracking Click Handler
/// </summary>
/// <param name="eventData"></param>
public void OnPointerClick(PointerEventData eventData)
{
counter++;
targetText.text = counter.ToString();
//throw new System.NotImplementedException();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
8. Attach the C# script on “TouchCube”
- Attach "HandTrack.cs" to “TouchCube”
- Set
Target TextonInspectorpanel toCounteron the scene.
- Set
9. Build
- Press
BuildformBuild Settingspanel - Install *.apk on Android or DevKit.

Top comments (0)