- Home /
Question by
Wakeful · Jun 23, 2014 at 10:21 AM ·
c#2dontriggerenterboxcollider2d
OnTriggerEnter2D Box Collider
Hey, is there a way to use OnTriggerEnter2D but it only detects 2D Box Colliders? I have a script that detects when the enemy loses health from a Sword. But I have two colliders on the enemy. Anyone think they can help? I want OnTriggerEnter2D to only detect 2D Box Colliders. Thx
Here is my script:
void OnTriggerEnter2D(Collider2D other) {
if (other.tag == "WSS" && SS.WSSA == true && damaged == false)
{
health = health - Random.Range(statsScript.weaponShortSwordMinDamage, statsScript.weaponShortSwordMaxDamage);
damaged = true;
Debug.Log(health);
}
}
Picture of my scene:
screenshot (54).png
(152.7 kB)
Comment
Best Answer
Answer by Pyrian · Jun 23, 2014 at 12:47 PM
Just add "&& other is BoxCollider2D" to your if statement.
Your answer
Follow this Question
Related Questions
Is there a way to find other's components using OnTriggerEnter? 1 Answer
AI Attack Not Working! W/Video 1 Answer
OnTriggerEnter2D with multiple objects 0 Answers
OnTriggerEnter 1 Answer
RayCasts and BoxCollider2D not working? 2 Answers