Touch the object with the index finger of your right hand.
Sample Repository
Run the sample
- Clone Sample Repository, Change current directory to
UCanTouchThis
. 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
on the Scene. - Put
NRHand_L
fromAssets
>NRSDK
>Prefabs
>Hands
toNRInput
>Left
on the Scene.
3. Disable NRHandPointer_R
- Select
NRHandPointer_R
fromNRInput
>Right
>NRHand_R
on the Scene. - Disable
NRHandPointer_R
from Inspector Panel. - Do the same settings for the Left hand (
NRHandPointer_L
) .
4. Create empty game objects
- Create an empty game object in the Scene with the name "HandController".
- Also, create an empty game object in the Scene with the name "Target".
- Set each GameObject's positions to 0.
-
Pos X
: 0,Pos Y
: 0,Pos Z
: 0
-
5. Make Alpha material
- Create Material on
Assets
- Change name to “AlphaMaterial”
- Change
Rendering Mode
item toFade
.
6. Create Sphere for hand tracking
- Put
Sphere
inHandController
.- Change name to “Hand_R_IndexTip”
-
Pos X
: 0,Pos Y
: 0,Pos Z
: 0 -
Scale
-
X
: 0.03 ,Y
: 0.03 ,Z
: 0.03
-
- Add component
Ridgitbody
.- Uncheck
Use Gravity
- Uncheck
- Set a material “AlphaMaterial” to
Materials
fromAssets
.
7. Create C# script for hand tracking extension
- Create
C# Script
in the asset with the file name "HandController.cs". - Write the code as follows.
using NRKernal;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Hand Controller for Tip
/// </summary>
public class HandController : MonoBehaviour
{
/// <summary>
/// IndexTip GameObject
/// </summary>
public GameObject hand_R_IndexTip;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// Get Right Hand
HandState handState = NRInput.Hands.GetHandState(HandEnum.RightHand);
// Get Index Tip Position of right hand
Vector3 handStateThumbTipPosition = handState.GetJointPose(HandJointID.IndexTip).position;
// Set Hand R IndexTip Sphere position
hand_R_IndexTip.transform.position = handStateThumbTipPosition;
}
}
8. Attach the C# script on “HandController”
- Attach "HandController.cs" to “HandController” game object
- Set
hand_R_IndexTip
onInspector
panel to “Hand_R_IndexTip” game object from the scene.
- Set
9. Create Cube as a target object
- Put
Cube
inTarget
.- Change name to “TargetCube1”
-
Pos X
: 0.1,Pos Y
: -0.05,Pos Z
: 0.8 -
Scale
-
X
: 0.1 ,Y
: 0.1 ,Z
: 0.1
-
- Add component
Ridgitbody
.- Uncheck
Use Gravity
- Uncheck
10. Create C# script for target game object
- Create
C# Script
in the asset with the file name "TargetCube.cs". - Write the code as follows.
using NRKernal;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
/// Target Cube Script
/// </summary>
public class TargetCube: MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// Display event log using console
/// </summary>
/// <param name="collision"></param>
void OnCollisionEnter(Collision collision)
{
Debug.Log("Hit!");
}
}
11. Attach the C# script on “Target”
- Attach "TargetCube.cs" to “TargetCube1” game object.
12. Build
- Press
Build
formBuild Settings
panel - Install *.apk on Android or DevKit.
Top comments (0)