- Home /
Question by
guenhyvar · Dec 23, 2015 at 04:31 PM ·
2dcollisiontriggerrigidbody2d
OnTriggerEnter2D problem on created collider2d and rigidbody2d during runtime
Hello! Noob here I just wanted to ask if what I'm doing is possible, I created a RigidBody2D and EdgeCollider2D on OnEnable() and at the same class there's a OnTriggerEnter2D and I don't know if I did something wrong or it's just not possible?
Here's my code hope it helps and thanks!:
void OnEnable(){
Rigidbody2D _edgeRigidBody = _edgeColliderContainer.AddComponent<Rigidbody2D> () as Rigidbody2D;
_edgeRigidBody.gravityScale = 0;
_edgeColliderContainer.name = "TestCollider";
_edgeColliderContainer.transform.position = gameObject.transform.position;
EdgeCollider2D _edgeCollider = _edgeColliderContainer.AddComponent<EdgeCollider2D> () as EdgeCollider2D;
_edgeCollider.isTrigger = true;
}
void OnTriggerEnter2D(Collider2D _Collider){
Debug.Log("Testing");
}
Comment
may be problem in _edgeColliderContainer.transform.position = gameObject.transform.position; check it.