This tutorial will guide you through setting up hands in VR. This tutorial uses the Oculus headset. In addition you must have the windows OS running and a PC strong enough to handle VR

Note: project file name: XRInteractableTwo

Introduction

We will continue using Unity's action based XR interaction toolkit. When using the XR interaction toolkit, there aren't any hands so you will need to create your own

⭐STEP 1: Add hands

  1. Import the VRHands.unitypackage by going to Assets > Import Package > Custom Package
  2. In the Hierarchy window > XR Rig > Camera Offset > LeftHand Controller and then in the Inspector window > Model >model prefab and from the Assets folder click on > VR Hands > Prefabs(which you imported in step #1) and drag and drop the Left Hand into the model prefab slot
  3. Once again in the Hierarchy window > XR Rig > Camera Offset > RightHand Controller and then in the Inspector window > Model >model prefab and from the Assets folder click on > VR Hands > Prefabs(which you imported in step #1) and drag and drop the Right Hand into the model prefab slot

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/27a79063-c67d-4ad2-93d5-73e0d612dca3/1.png

  1. Now lets write a script. In the Scripts folder > Right click > Create > C# Script > Rename it HandController

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class HandController : MonoBehaviour
{
    [SerializeField] private InputActionAsset actionAsset;
    [SerializeField] private string controllerName;
    [SerializeField] private string actionNameTrigger;
    [SerializeField] private string actionNameGrip;
    public InputActionReference actionReference;
    private InputActionMap _actionMap;
    private InputAction _inputActionTrigger;
    private InputAction _inputActionGrip;

    private Animator _handAnimator;

    // Start is called before the first frame update
    void Awake()
    {
        //get all of our actions...
        _actionMap = actionAsset.FindActionMap(controllerName);
        _inputActionGrip = _actionMap.FindAction(actionNameGrip);
        _inputActionTrigger = _actionMap.FindAction(actionNameTrigger);

        //get the Animator
        _handAnimator = GetComponent<Animator>();
    }

    private void OnEnable()
    {
        _inputActionGrip.Enable();
        _inputActionTrigger.Enable();
    }
    private void OnDisable()
    {
        _inputActionGrip.Disable();
        _inputActionTrigger.Disable();
    }

    // Update is called once per frame
    void Update()
    {
        var gripValue = _inputActionGrip.ReadValue<float>();
        var triggerValue = _inputActionTrigger.ReadValue<float>();

        _handAnimator.SetFloat("Grip", gripValue);
        _handAnimator.SetFloat("Trigger", triggerValue);

    }
}
  1. Now Drag and drop the script onto the Left Hand prefab. So go to Assets folder click on > VR Hands > Prefabs and click on the Left Hand prefab and drag and drop the HandController.cs script into the Inspector window for the Left Hand

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/df4ccd97-4359-47e8-8ef9-eacd5633f595/2.png

  1. Change the values for the Action Asset, Controller Name, Action Name Trigger, Action Name Grip properties as shown above

  2. In the Hierarchy window > XR Rig > Camera Offset > LeftHand Controller go to the Inspector window and uncheck the Line Renderer and XR Interactor Line Visual boxes

  3. Also under the XR Ray Interactor change Hit Detection Type to Sphere cast and change the Sphere Cast Radius to 0.013

  4. In the Hierarchy window > XR Rig > Camera Offset > RightHand Controller go to the Inspector window and uncheck the Line Renderer and XR Interactor Line Visual boxes

  5. Also under the XR Ray Interactor change Hit Detection Type to Sphere cast and change the Sphere Cast Radius to 0.013

⭐STEP 2: A Make your scene/enviornment