Log in or register to post comments

GUI Button

August 5, 2011 - 10:00pm #1

Can someone please provide me a detailed workflow of how to create a button that will appear on the mobile device screen as soon as the Android app loads?

For example, if this is the correct script, then what do I do with it? Where does it go? Additionally, what script do I use to get the button to do what I want?

function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
print ("You clicked the button!");
}
}

Many thanks.

Re: GUI Button

August 19, 2011 - 3:38am #4

thank you very much!! :)

Re: GUI Button

August 18, 2011 - 9:20am #3

@ giancamati, QCAR virtual buttons are something else. You can "press" a "button" on the marker and make something happen. But I don't think that is what heavy means.

@heavy, That is the correct script indeed. Take a look here:
http://unity3d.com/support/documentation/Components/gui-Basics.html
Create an empty game object, then create an empty script (C# or JS) and attach that script to the empty game object. Now copy that code to the bottom of the script (if using JS) or at the bottom of the MonoBehaviour class if using C#.

Now you will see the bottom appear over your QCAR camera output. If you want the button to appear dynamically, you will have to write some more code. Just put an if statement in the OnGUI function to decide whether or not to actually draw the button.

"what script do I use to get the button to do what I want?" Well, that depends on what you want to do. If you want to draw the text "You clicked the button!" then that script is just for you. But I am sure you want to do something more cool than that. But this is beyond the scope of this topic. That is basically the same as asking "how to I write a game?". Just make a function of whatever you want to do when your button is clicked and put the function call at the location of "print ("You clicked the button!");"

Re: GUI Button

August 18, 2011 - 2:18am #2

I am interested in it as well, but I believe that QCAR API provides an example of virtual buttons.

:)

Log in or register to post comments