Log in or register to post comments

a problem with virtualbutton

March 26, 2012 - 11:55pm #2

hello

i want to touch a virtual button to create a GUIbutton with text "ship,see more info." on the phone screen .

here is my code

using UnityEngine;
using System.Collections.Generic;

public class VirtualButtonEventHandler : MonoBehaviour,
                                         IVirtualButtonEventHandler
{

 

    private GameObject mship;
 
    void Start()
    {
       
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbs.Length; ++i)
        {
            vbs[i].RegisterEventHandler(this);
        }
        mship = transform.FindChild("ship").gameObject;

		mship.active = true;
    }


    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {

 
        switch (vb.VirtualButtonName)
        {
            case "vbname1":
		GUI.Box(new Rect(50,50,200,180), "Menu");

		if(GUI.Button(new Rect(60,60,160,40), "ship,see more info.")) {
			Application.OpenURL("http://*****.com");
		}
	break;
             case "vbname2":
                    //waiting add;

	break;
             case "vbname3":
                    //waiting add;
	break;

}

but it doesn't works , when i touch the virtual button , the 3d model disappears!

can anyone help? thanks very much!!

Re: a problem with virtualbutton

March 27, 2012 - 6:23pm #1

I believe GUI methods can only be called from the OnGUI callback:

http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnGUI.html

- Kim

Log in or register to post comments