Hold Me Tight – MR Tutorial for Nreal Light

Now let’s try to grab the touched GameObject and move it. This tutorial is a continuation of the “U Can Touch This” tutorial. If you have not yet comple “U Can Touch This”, please proceed with the following tutorial first.

U Can Touch This – MR Tut…


This content originally appeared on DEV Community and was authored by DEV Community

Completion screen of sample

Now let's try to grab the touched GameObject and move it. This tutorial is a continuation of the "U Can Touch This" tutorial. If you have not yet comple "U Can Touch This", please proceed with the following tutorial first.

Sample Repository

Run the sample

  1. Clone Sample Repository, Change current directory to HoldMeTight. And Open with Unity.
  2. (If you don’t have NRSDK) Download NRSDK 1.7.0 from https://nreal-public.nreal.ai/download/NRSDKForUnityAndroid_1.7.0.unitypackage
  3. Open Build Setting, change Platform to Android
  4. Open Project, select Assets > import package > Custom Package and import NRSDKForUnityAndroid_1.7.0.unitypackage.
  5. Check Build Settings > Player Settings by referring to Configure Build Settings
  6. Press Build form Build Settings panel
  7. Install *.apk on Android or DevKit.

Tutorial

1. First, complete "U Can Touch This"

  • First, complete "U Can Touch This". This tutorial will continue with "U Can Touch This". You can also start by cloning the sample repository.

2. Check “Is Trigger” on “TargetCube1”

  • Select TargetCube1 from Target on the Scene.
  • Check Is Trigger from Inspector Panel. By checking this box, you can trigger events when you touch game objects.

3. Chenge C# Script

  • Open C# Script “TargetCube.cs” on Assets panel.
  • Change 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
{
    private MeshRenderer meshRender;

    void Awake()
    {
        meshRender = transform.GetComponent<MeshRenderer>();
    }

    // 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>
    private void OnCollisionEnter(Collision other)
    {
        Debug.Log("Hit!");
    }

    /// <summary>
    /// Trigger Enter Event Handler
    /// </summary>
    /// <param name="other"></param>
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Enter!");
        meshRender.material.color = new Color(1f, 0f, 0f);
    }

    /// <summary>
    /// Trigger Stay Event Handler
    /// </summary>
    /// <param name="other"></param>
    private void OnTriggerStay(Collider other)
    {
        // Get Right Hand
        HandState handState = NRInput.Hands.GetHandState(HandEnum.RightHand);
        if(handState.currentGesture == HandGesture.Grab)
        {
            // Get Index Tip Position of right hand
            Vector3 handStateThumbTipPosition = handState.GetJointPose(HandJointID.IndexTip).position;
            // Set Hand R IndexTip Sphere position
            transform.position = handStateThumbTipPosition;
        }
    }

    /// <summary>
    /// Trigger Exit Event Handler
    /// </summary>
    /// <param name="other"></param>
    private void OnTriggerExit(Collider other)
    {
        Debug.Log("Exit!");
        meshRender.material.color = new Color(1f, 1f, 1f);
    }
}

4. Run the tutorial

  • Press Play button and run the tutorial.

5. Build

  1. Press Build form Build Settings panel
  2. Install *.apk on Android or DevKit.


This content originally appeared on DEV Community and was authored by DEV Community


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2022-03-11T22:25:13+00:00) Hold Me Tight – MR Tutorial for Nreal Light. Retrieved from https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/

MLA
" » Hold Me Tight – MR Tutorial for Nreal Light." DEV Community | Sciencx - Friday March 11, 2022, https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/
HARVARD
DEV Community | Sciencx Friday March 11, 2022 » Hold Me Tight – MR Tutorial for Nreal Light., viewed ,<https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/>
VANCOUVER
DEV Community | Sciencx - » Hold Me Tight – MR Tutorial for Nreal Light. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/
CHICAGO
" » Hold Me Tight – MR Tutorial for Nreal Light." DEV Community | Sciencx - Accessed . https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/
IEEE
" » Hold Me Tight – MR Tutorial for Nreal Light." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/. [Accessed: ]
rf:citation
» Hold Me Tight – MR Tutorial for Nreal Light | DEV Community | Sciencx | https://www.scien.cx/2022/03/11/hold-me-tight-mr-tutorial-for-nreal-light/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.