The script I have here is attached to the falling cube, and is using a Sphere collider with trigger unmarked. It is attached to a prefab that is instantiated above the screen and dropped into the scene. The idea is that once it reaches it's intended Y value it will enable the boolean "canKill" and will destroy any trigger items it is touching. I have not been able to get the triggers to recognize an OnTriggerEnter or OnTriggerStay. What am I doing wrong?
Below is the script attached to the falling cube.
private var yVal : int;
var speedToDrop : float = 10;
static var canKill : boolean = false;
private var inBlastRadius : boolean = false;
function Awake ()
{
yVal = crossHair.dynamiteY;
}
function Update ()
{
var thisVector3 : Vector3 = this.transform.position;
if(thisVector3.y <= yVal)
{
canKill = true;
Destroy(this.gameObject);
}
this.transform.Translate(0, 0, speedToDrop * Time.deltaTime);
}
function OnTriggerEnter(hit : Collider)
{
Debug.Log("Entered");
inBlastRadius = true;
if(canKill && inBlastRadius)
{
Destroy(gameObject);
}
}
function OnTriggerExit(hit : Collider)
{
inBlastRadius = false;
}
function OnTriggerStay(hit : Collider)
{
Debug.Log("In trigger");
inBlastRadius = true;
if(canKill && inBlastRadius)
{
Destroy(gameObject);
}
}
The other cube is moving horizontally across the screen with a sphere collider marked Trigger.