Search Unity

Virtual Button, On pressed and On release

Discussion in 'AR/VR (XR) Discussion' started by louisonatundu, Nov 20, 2019.

  1. louisonatundu

    louisonatundu

    Joined:
    Nov 20, 2019
    Posts:
    1
    Hello,
    I created a virtual button, It working well, with two elements, Cube and Sphere, when I pressed a Virtual Button a cube element disappear and sphere element appear, in the C# script I have made I released the Virtual button the sphere element is supposed to disappear and the cube element appear but the issue is that the sphere element stay.
    Some one can help me please ?

    That is my C# Script :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Vuforia;
    5.  
    6. public class VirtualButtonScript : MonoBehaviour, IVirtualButtonEventHandler
    7. {
    8.     public GameObject spherego, cubego;
    9.     VirtualButtonBehaviour vrb;
    10.    
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         vrb = GetComponentInChildren<VirtualButtonBehaviour>();
    15.         vrb.RegisterEventHandler(this);
    16.         cubego.SetActive(true);
    17.         spherego.SetActive(false);
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.        
    24.     }
    25.  
    26.     public void OnButtonPressed(VirtualButtonBehaviour vb)
    27.     {
    28.         cubego.SetActive (false);
    29.         spherego.SetActive (true);
    30.     }
    31.  
    32.     public void OnButtonReleased(VirtualButtonBehaviour vb)
    33.     {
    34.         cubego.SetActive (true);
    35.         spherego.SetActive (false);
    36.     }
    37.  
    38. }
    39.  
    Bellow Is image, in red : Virtual Button, in green : Cube in Yellow : Sphere

    upload_2019-11-20_12-42-27.png

    Thanks
     

    Attached Files:

  2. bandhanmishra2912

    bandhanmishra2912

    Joined:
    Nov 8, 2022
    Posts:
    1
    I'm certainly sure that you made the right script except for the fact that you initialized VirtualButtonBehaviour "vrb" and when you call it you are using VirtualButtonBehaviour "vb". Try changing it. i guess that should do the trick