Button

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
<code>// Use this script on a guiTexture object for regular push buttons
+
<js>
<br>// that behave properly like Mac OS X.
+
// Use this script on a guiTexture object for regular push buttons
<br>
+
// that behave properly like Mac OS X.
<br>var normalMaterial : Material;
+
 
<br>var hoverMaterial : Material;
+
var normalMaterial : Material;
<br>var pressedMaterial : Material;
+
var hoverMaterial : Material;
<br>var messagee : GameObject;
+
var pressedMaterial : Material;
<br>var message = "ButtonPress";
+
var messagee : GameObject;
<br>
+
var message = "ButtonPress";
<br>private var state = 0;
+
 
<br>
+
private var state = 0;
<br>function OnMouseEnter()
+
 
<br>{
+
function OnMouseEnter()
<br> state++;
+
{
<br> if (state == 1)
+
state++;
<br> guiText.material = hoverMaterial;
+
if (state == 1)
<br>}
+
guiText.material = hoverMaterial;
<br>
+
}
<br>function OnMouseDown()
+
 
<br>{
+
function OnMouseDown()
<br> state++;
+
{
<br> if (state == 2)
+
state++;
<br> guiText.material = pressedMaterial;
+
if (state == 2)
<br>}
+
guiText.material = pressedMaterial;
<br>
+
}
<br>function OnMouseUp()
+
 
<br>{
+
function OnMouseUp()
<br> if (state == 2)
+
{
<br> {
+
if (state == 2)
<br> state--;
+
{
<br> if (messagee)
+
state--;
<br> messagee.SendMessage(message, gameObject);
+
if (messagee)
<br> }
+
messagee.SendMessage(message, gameObject);
<br> else
+
}
<br> {
+
else
<br> state --;
+
{
<br> if (state < 0)
+
state --;
<br> state = 0;
+
if (state < 0)
<br> }
+
state = 0;
<br> guiText.material = normalMaterial;
+
}
<br>}
+
guiText.material = normalMaterial;
<br>
+
}
<br>function OnMouseExit()
+
 
<br>{
+
function OnMouseExit()
<br> if (state > 0)
+
{
<br> state--;
+
if (state > 0)
<br> if (state == 0)
+
state--;
<br> guiText.material = normalMaterial;
+
if (state == 0)
<br>}
+
guiText.material = normalMaterial;
</code>
+
}
 +
 
 +
</js>

Revision as of 01:35, 1 December 2005

<js> // 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; }

</js>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox