Button

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Usage)
Line 7: Line 7:
 
Use this script on a guiTexture object for regular push buttons that behave properly like Mac OS X.  FIXME
 
Use this script on a guiTexture object for regular push buttons that behave properly like Mac OS X.  FIXME
 
==Usage==
 
==Usage==
Use this script on a guiTexture object for regular push buttons that behave properly like Mac OS X. FIXME
+
Attach this script to a GuiTexture object. Add a ButtonPressed function to the same object to catch when the button has been pressed.
  
 
==JavaScript - Button.js==
 
==JavaScript - Button.js==

Revision as of 05:05, 7 December 2005

Author: Jonathan Czeck (aarku)

Description

Use this script on a guiTexture object for regular push buttons that behave properly like Mac OS X. FIXME

Usage

Attach this script to a GuiTexture object. Add a ButtonPressed function to the same object to catch when the button has been pressed.

JavaScript - Button.js

<javascript>

var normalMaterial : Material;
var hoverMaterial : Material;
var pressedMaterial : Material;
var messagee : GameObject;
var message = "ButtonPress";

private var state = 0;

function OnMouseEnter()
{
	state++;
	if (state == 1)
		guiText.material = hoverMaterial;
}

function OnMouseDown()
{
	state++;
	if (state == 2)
		guiText.material = pressedMaterial;
}

function OnMouseUp()
{
	if (state == 2)
	{
		state--;
		if (messagee)
			messagee.SendMessage(message, gameObject);
	}
	else
	{
		state --;
		if (state < 0)
			state = 0;
	}
	guiText.material = normalMaterial;
}

function OnMouseExit()
{
	if (state > 0)
		state--;
	if (state == 0)
		guiText.material = normalMaterial;
}

</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox