Button

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(JavaScript - Button.js)
(Description)
Line 5: Line 5:
 
Author: Jonathan Czeck (aarku)
 
Author: Jonathan Czeck (aarku)
 
==Description==
 
==Description==
This script uses a GuiTexture an Unity mouse events to implement a regular push button that behaves properly like Mac OS X.
+
This script uses a GuiTexture and Unity mouse events to implement a regular push button that behaves properly like Mac OS X.
  
 
==Usage==
 
==Usage==

Revision as of 05:39, 9 December 2005

Author: Jonathan Czeck (aarku)

Description

This script uses a GuiTexture and Unity mouse events to implement a regular push button that behaves properly like Mac OS X.

Usage

Attach this script to a GuiTexture object. Add a ButtonPressed function to the object pointed to by the messagee variable to catch when the button has been pressed. (You can change the name of the function by changing the message variable.)

JavaScript - Button.js

<javascript>

var normalTexture : FileTexture;
var hoverTexture : FileTexture;
var pressedTexture : FileTexture;
var messagee : GameObject;
var message = "ButtonPressed";

private var state = 0;
private var myGUITexture : GUITexture;
myGUITexture = GetComponent(GUITexture); 
function OnMouseEnter()
{
	state++;
	if (state == 1)
		myGUITexture.texture = hoverTexture;
}

function OnMouseDown()
{
	state++;
	if (state == 2)
		myGUITexture.texture = pressedTexture;
}

function OnMouseUp()
{
	if (state == 2)
	{
		state--;
		if (messagee)
			messagee.SendMessage(message, gameObject);
	}
	else
	{
		state --;
		if (state < 0)
			state = 0;
	}
	myGUITexture.texture = normalTexture;
}

function OnMouseExit()
{
	if (state > 0)
		state--;
	if (state == 0)
		myGUITexture.texture = normalTexture;
}

</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox