Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Touching an object using Oculus integration hand tracking to trigger an animation

Discussion in 'Getting Started' started by tscarbzz, Apr 26, 2022.

  1. tscarbzz

    tscarbzz

    Joined:
    Feb 12, 2022
    Posts:
    1
    Hi there. I'm fairly new to Unity and I've been messing around with the hand tracking prefabs in the new Oculus integration package. I'm not sure how complex this is, but I've been trying to trigger a simple animation that I've made (just a cube moving back and fourth) that the user activates by touching this cube with the OVRHand Prefabs. I'm not quite sure where I'm going wrong. I have limited experience with scripting, but I followed a tutorial for the following code that uses booleans as parameters.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayCube : MonoBehaviour
    6. {
    7.     [SerializeField] private Animator CubeController;
    8.     private void OnTriggerEnter(Collider other)
    9.     {
    10.         if (other.CompareTag("Hand"))
    11.             {
    12.         CubeController.SetBool("CubeMove", true);
    13.         }
    14.     }
    15.     private void OnTriggerExit(Collider other)
    16.     {
    17.         if (other.CompareTag("Hand"))
    18.             {
    19.             CubeController.SetBool("CubeMove", false);
    20.         }
    21.     }
    22. }
    I tried adding this script to the prefabs, but I'm not sure if I've added it to the right place, since the hierarchy is so full of different things relating to the hand tracking (see the attached screenshot). I also know if it's necessary to add some kind of collider to the hands, again I'm not entirely sure what to do here.

    Any help would be appreciated.
     

    Attached Files:

    Pseudonym-Username likes this.