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 Package
and importNRSDKForUnityAndroid_1.8.0.unitypackage
. - Check
Build Settings
>Player Settings
by referring to Configure Build Settings - Press
Build
formBuild Settings
panel - 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 Package
and importNRSDKForUnityAndroid_1.8.0.unitypackage
.
2. Setting for HandTracking to NRInput
- Select
NRInput
, and changeInput Source Type
toHands
- Put
NRHand_R
fromAssets
>NRSDK
>Prefabs
>Hands
toNRInput
>Right
- Put
NRHand_L
fromAssets
>NRSDK
>Prefabs
>Hands
toNRInput
>Left
3. Create Material
- Open
Project
, selectAssets
- Create
Material
onAssets
- Change name to “TouchCubeMaterial”
- Change
Albedo
to “CC0000”
4. Put Cube in the Scene
- Put
Cube
in the Scene- Change name to “TouchCube”
-
Pos X
: 0,Pos Y
: 0,Pos Z
: 8
5. Put a Canvas in the scene
- Put
Canvas
fromCreate
>UI
- Set property on
Inspector
panel-
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
Text
as a child ofCanvas
with the name "Counter”.-
Pos X
: 0,Pos Y
: -30,Pos Z
: 3 - Change
Text
to “0” - Change
Color
to “FFCC00” - Change Font size to 30
-
7. Create C# Script in Assets
- Create
C# Script
in 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 Text
onInspector
panel toCounter
on the scene.
- Set
9. Build
- Press
Build
formBuild Settings
panel - Install *.apk on Android or DevKit.
Top comments (0)