Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Hand washing Leap Motion

Discussion in 'AR' started by crosswire89, Jan 9, 2023.

  1. crosswire89

    crosswire89

    Joined:
    Dec 13, 2022
    Posts:
    3
    Hi can someone help me please.

    I'm trying to create hand washing tutorial using Leap Motion Hand Motion Controller but seems to be getting stuck and not much tutorial online in getting the hand hand to turn the tap on and off.
    I have a water particle system. I just want the hand to touch the side of the tap, water comes on. touch it again again and it shuts off.

    if sounds very easy but seems to be very complicated for me.

    upload_2023-1-9_12-27-7.png

    Here is my script below

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class WaterTap : MonoBehaviour
    5. {
    6.     private AudioSource source;
    7.     public AudioClip buttonSound;
    8.     private bool on = false;
    9.     private bool buttonHit = false;
    10.     private GameObject ButtonCold;
    11.     private float buttonDownDistance = 0.025f;
    12.     private float buttonReturnSpeed = 0.001f;
    13.     private float buttonOriginalY;
    14.     public ParticleSystem WaterDroplets;
    15.     private float buttonHitAgainTime = 0.5f;
    16.     private float canHitAgain;
    17.     {
    18.     source = gameObject.AddComponent<AudioSource>();
    19.     button = transform.GetChild(0).gameObject;
    20.     buttonOriginalY = button.transform.position.x;
    21.     WaterDroplets.enable = false;
    22. }
    23.     void Update ()
    24. {
    25.     if (buttonHit == true)
    26.     {
    27.         source.Waterrunning(buttonSound);
    28.         buttonHit = false;
    29.         on = !on;
    30.         button.transform.position = new Vector3(button.transform.position.x, button.transform.position.y - buttonDownDistance, button.transform.position.z);
    31.         if (on)
    32.         {
    33.             WaterDroplets.enable = true;
    34.         }
    35.         else
    36.         {
    37.             WaterDroplets.enable = false;
    38.         }
    39.     }
    40.     if (button.transform.position.x < buttonOriginalY)
    41.     {
    42.         button.transform.position += new Vector3(0, buttonReturnSpeed, 0);
    43.     }
    44. }
    45.    private void OnTriggerEnter(Collider other)
    46. {
    47.     if (other.CompareTag ("PlayerHand") && canHitAgain < Time.time)
    48.     {
    49.         canHitAgain = Time.time + buttonHitAgainTime;
    50.         buttonHit = true;
    51.     }
    52.   }
    53. }

    can someone tell me what I'm doing wrong.
     
    Last edited: Jan 10, 2023
  2. crosswire89

    crosswire89

    Joined:
    Dec 13, 2022
    Posts:
    3
    upload_2023-1-9_12-49-25.png

    upload_2023-1-9_12-49-44.png

    also with these errors Thanks
     

    Attached Files:

  3. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    609
    hey, you need to insert your code with the "insert code" functionality of the forum to make it readable.

    Besides this, you should do some basic scripting and C# tutorial before you post. Seems you have basic syntactic errors in your script, so it does not even compile.
     
    crosswire89 likes this.
  4. crosswire89

    crosswire89

    Joined:
    Dec 13, 2022
    Posts:
    3
    I did take some basic scripting tutorial on YouTube, there isn't much for leap motion. I'm using a VR tutorial and replicate it for AR Leap Motion. The script I used was a YouTube tutorial.


    if there something I've added or missed. as a beginner, will need help.
     
  5. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    609
    First get sure that the class compiles. Visual studio should show you compile errors.
    This does nothing have to do with AR or hand tracking, though. This is basic scripting stuff.
     
    crosswire89 likes this.
  6. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    525
    On line 17 you have an opening brace that I'm pretty sure you don't intend to be there. This looks like it was supposed to be part of an Awake or Start method? If you need help brushing up on basics of C# scripting in Unity, I'd recommend checking out Unity Learn or some of the great stuff from the community on YouTube.
     
    crosswire89 likes this.