- Home /
Question by
jimpa1986 · Jan 10, 2014 at 11:59 AM ·
physicsontriggerenter2d-physicstriggers
Why doesn't the OnTriggerStay2D run?
Why doesn't the OnTriggerStay2D run?? The object that collides with the trigger has both a collider and a rigidbody attached. (does it have to have a rigid body?)
#pragma strict
public var hasGravity : boolean;
public var mass : float = 5;
public var reachFactor : float = 5;
function Start () {
gameObject.AddComponent(CircleCollider2D);
gameObject.GetComponent(CircleCollider2D).isTrigger = true;
gameObject.GetComponent(CircleCollider2D).radius = mass * reachFactor;
}
public function OnTriggerStay(coll: Collider) {
Debug.Log("Sent");
if (coll.gameObject.GetComponent(affected_by_gravity)) {
coll.gameObject.GetComponent(affected_by_gravity).pull(mass, Vector2(gameObject.transform.position.x,gameObject.transform.position.y));
}
}
Comment