Creating a window with a button

Is it possible to create a window with a button (like a mouseover button) that is connected to an object in the game? Basically, when you click the button it does something.

Sure, create a button, have a public variable where you define what object is affected and then when the user clicks the button do whatever you want with it.

thats actually how it works by default, you code what the button does and what it affects

How do you create a button? I’ve been exploring the engine trying to find out how to do this.

Check out the script reference on the class GUI

you do it all from script

So I would need to go to GameObject > Create Other > GUI Text and make a script from there?

I was looking at this: Unity - Manual: IMGUI Basics
but it doesn’t explain how to actually create a script object in order for the button to show up.

You just need to create a JavaScript file (menu Assets > Create > JavaScript) and paste one of the code examples from the GUI Basics page. You attach the script to an object in the scene by dragging the script file onto the object in the inspector. If you want to go further with the GUI, you can find explanations with code samples for all the controls on this manual page.

Okay, I got the buttons showing up, however, I can’t seem to get a message to show up when you click the button as per this example:

private var selectedToolbar : int = 0;
private var toolbarStrings = ["One", "Two"];

function OnGUI () {
	// Determine which button is active, whether it was clicked this frame or not
	selectedToolbar = GUI.Toolbar (Rect (50, 10, Screen.width - 100, 30), selectedToolbar, toolbarStrings);

	// If the user clicked a new Toolbar button this frame, we'll process their input
	if (GUI.changed)
	{
		print ("The toolbar was clicked");

		if (selectedToolbar == 0)
		{
			print ("First button was clicked");
		}
		else
		{
			print ("Second button was clicked");
		}
	}
	
	
}

Where on the screen does the “Print” text output to? Is there a way to set the coordinates of the “Print” texts so it shows up on the screen?

The print statement is only for debugging purposes - the text gets output to the status bar and console window (menu Window > Console). You need to use the functions of the GUI class to display text, but this might involve a bit of work if you want a scrolling console type display.

Well no, I don’t want anything fancy, I just want some text to display to the screen when you click a button, that’s all.

In that case, you can probably just use GUI.Label.