Button

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
 
that behave properly like Mac OS X.
 
that behave properly like Mac OS X.
 
----
 
----
 
+
var normalMaterial : Material;
+
var normalMaterial : Material;
var hoverMaterial : Material;
+
var hoverMaterial : Material;
var pressedMaterial : Material;
+
var pressedMaterial : Material;
var messagee : GameObject;
+
var messagee : GameObject;
var message = "ButtonPress";
+
var message = "ButtonPress";
 
+
private var state = 0;
+
private var state = 0;
 
+
function OnMouseEnter()
+
function OnMouseEnter()
{
+
{
state++;
+
state++;
if (state == 1)
+
if (state == 1)
guiText.material = hoverMaterial;
+
guiText.material = hoverMaterial;
}
+
}
 
+
function OnMouseDown()
+
function OnMouseDown()
{
+
{
state++;
+
state++;
if (state == 2)
+
if (state == 2)
guiText.material = pressedMaterial;
+
guiText.material = pressedMaterial;
}
+
}
 
+
function OnMouseUp()
+
function OnMouseUp()
{
+
{
if (state == 2)
+
if (state == 2)
{
+
{
state--;
+
state--;
if (messagee)
+
if (messagee)
messagee.SendMessage(message, gameObject);
+
messagee.SendMessage(message, gameObject);
}
+
}
else
+
else
{
+
{
state --;
+
state --;
if (state < 0)
+
if (state < 0)
state = 0;
+
state = 0;
}
+
}
guiText.material = normalMaterial;
+
guiText.material = normalMaterial;
}
+
}
 
+
function OnMouseExit()
+
function OnMouseExit()
{
+
{
if (state > 0)
+
if (state > 0)
state--;
+
state--;
if (state == 0)
+
if (state == 0)
guiText.material = normalMaterial;
+
guiText.material = normalMaterial;
}
+
}

Revision as of 01:57, 1 December 2005

Author: Jon (Aarku)


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


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;
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox