Log in or register to post comments

Gameobject instead of button?

February 7, 2016 - 11:53am #1
Hi,
 
I am completely new to C# and I've been looking on the internet, for a few days without any luck, how to hide a gameobject when a target is tracked. I found something similar to what I want to do in the FAQ section but using GUI button. The post says that is it possible to adapt the code to show a label, a menu, etc instead of a button but I did not found how to do that :
 
using UnityEngine;
using System.Collections;
using Vuforia;
 
public class ButtonPopup : MonoBehaviour, ITrackableEventHandler {
   
  private TrackableBehaviour mTrackableBehaviour;
   
  private bool mShowGUIButton = false;
  private Rect mButtonRect = new Rect(50,50,120,60);
   
  void Start () {
    mTrackableBehaviour = GetComponent<TrackableBehaviour>();
    if (mTrackableBehaviour) {
      mTrackableBehaviour.RegisterTrackableEventHandler(this);
    }
  }
   
  public void OnTrackableStateChanged(
      TrackableBehaviour.Status previousStatus,
      TrackableBehaviour.Status newStatus)
  {
    if (newStatus == TrackableBehaviour.Status.DETECTED ||
        newStatus == TrackableBehaviour.Status.TRACKED ||
        newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
    {
      mShowGUIButton = true;
    }
    else
    {
      mShowGUIButton = false;
    }
  }
   
  void OnGUI() {
    if (mShowGUIButton) {
      // draw the GUI button
      if (GUI.Button(mButtonRect, "Hello")) {
        // do something on button click 
      }
    }
  }
}

 

I will really appreciate if someone has a link to an example or even any lead on how to do that. Thank you!

Log in or register to post comments