Log in or register to post comments

Virtual Button Show/Hide an Object

November 29, 2012 - 8:25am #1

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;

        }

    }

 

 

Virtual Button Show/Hide an Object

November 29, 2012 - 8:51am #2

Hi, can you post this in the Unity section of this Forum please ?

Thanks!

Log in or register to post comments