"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Virtual Button Show/Hide an Object

Hey guys im faily new to using code in unity and im trying out VB's. Im want to have a button that i can press that will just turn off the model being displayed and then can be pressed again to turn it back on. This is what ive got so far. My script is call Button.cs

 

using UnityEngine;

using System.Collections;

 

public class VirtualButtonHandler : MonoBehaviour, IVirtualButtonEventHandler{

 

    private GameObject P90;

 

// Use this for initialization

void Start () {

// Register with the virtual buttons TrackableBehaviour

        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();

        for (int i = 0; i < vbs.Length; ++i)

        {

            vbs[i].RegisterEventHandler(this);

        }

 

        // Get handle to the object

        cube = GameObject.Find("P90").gameObject;

 

}

 

    // Called when the virtual button has just been pressed:

    public void OnButtonPressed(VirtualButtonBehaviour vb)

    {

        Debug.Log("OnButtonPressed");

 

        // Add the material corresponding to this virtual button

        // to the active material list:

        switch (vb.VirtualButtonName)

        {

            case "green":

                P90.renderer.enabled = false

            break;

        }

    }

 

 

    // Called when the virtual button has just been released:

    public void OnButtonReleased(VirtualButtonBehaviour vb)

    {

 

        // Remove the material corresponding to this virtual button

        // from the active material list:

        switch (vb.VirtualButtonName)

        {

            case "green":

                P90.renderer.enabled = true

                break;

        }

    }