- Home /
Problem with OnTriggerEnter
need help guys,, make explosion script, but it not work. i want, when player touch cube with collider as a Trigger then the Cube explode and player thrown, this my script :
void OnTriggerEnter (Collision col)
{
ExplosionWork (col.contacts [0].point);
// please help me to change this to "Void OnTriggerEnter"
}
public void ExplosionWork(Vector3 explosionPoint)
{
hitColliders = Physics.OverlapSphere (explosionPoint, blastRadius, explosionLayers);
foreach (Collider hitCol in hitColliders)
{
if(hitCol.GetComponent<Rigidbody>())
{
hitCol.GetComponent<Rigidbody>().isKinematic = false;
hitCol.GetComponent<Rigidbody>().AddExplosionForce(explosionPower, explosionPoint, blastRadius, 0, ForceMode.Impulse);
}
}
}
Thanks, Have a nice day
Answer by Chamandana · Jun 13, 2016 at 06:51 AM
As I know, basically you have two states of OnTriggerEnter methods, the normal (3D) one and the 2D one, which can be referred to as,
public void OnTriggerEnter2D (Collider2D otherOBJ){ }
public void OnTriggerEnter (Collider otherOBJ) { }
Then the object can be accessed as,
otherOBJ.gameObject
Answer by Brijs · Jun 13, 2016 at 06:22 AM
Correct signature of OnTriggerEnter
Change OnTriggerEnter(Collision col) to OnTriggerEnter(Collider col)
For more help : OnTriggerEnter Method
Your answer
Follow this Question
Related Questions
Objects do not destroy on Collision 1 Answer
Point of contact on other object in OnTriggerEnter 1 Answer
How can I compare Collider's layer to my LayerMask type variable? 2 Answers
Collection Using "GetComponent" 1 Answer
How to find the point of contact with the function OnTriggerEnter??? 4 Answers