#pragma strict

var Tag : String = "Player";
var Action : String = "Action";
var Param : String = "";
var Once : boolean = false;

private var Hit : boolean = false;

function PointInTrigger( pt : Vector3 )
{
	var q : float = 0.5;
	var local : Vector3 = transform.worldToLocalMatrix.MultiplyPoint3x4( pt );
	return
		local.x >= -q && local.x <= q &&
		local.y >= -q && local.y <= q &&
		local.z >= -q && local.z <= q
	;
}

function Start()
{
}

function Update()
{
	var objects = GameObject.FindGameObjectsWithTag( Tag );
	for( var obj : GameObject in objects )
	{
		var pos : Vector3 = obj.transform.position;
		if( PointInTrigger( pos ) && ( !Once || !Hit ) )
		{
			obj.SendMessage( Action, Param );
			Hit = true;
		}
	}
}

function OnDrawGizmos()
{
	Gizmos.color = Color(0.8,0.2,0,0.5);
	Gizmos.matrix = transform.localToWorldMatrix;
	Gizmos.DrawWireCube( Vector3(0,0,0), Vector3(1,1,1) );
}
