- Home /
Can I have two colliders attatched to my enemy that do different things and if so how?,Is it possible to have two colliders for one object
My situation is that I have a CircleCollider2D that when it is entered causes my enemy to chase the player. This works well however, I want to also have a BoxCollider2D that when the player enters will switch scene to my scene called "BattleScene". Please could anyone help. Thanks.I want it so that when my player enters the circle collider my enemy will follow him however when the player gets closer and enters the box collider (both attached to enemy) it will switch scenes to my scene called BattleScene.
Another alternitive i thought of was using a rigid body collision but I don't know that either.
Answer by musicalbulltz · Jan 01, 2019 at 05:54 AM
Yes you can do it . You just have to set your box collider as trigger so that when you call onTriggerEnter method unity gets notified about the collider you using and then you can load your battle scene inside the trigger enter method. Just set your box collider as trigger from inspector menu.
@musicalbulltz -- In the Enemy script, if you have an OnTriggerEnter (Collider other) then "other" refers to the Player's Collider in this case. It doesn't tell you which Collider on the Enemy that was entered.
Answer by Ady_M · Jan 01, 2019 at 02:36 PM
This seems to work fine:
Make sure that the Enemy's colliders are separate objects that have the Enemy as parent.
Give each collider a script with OnTrigger methods.
If the Collider scripts need access to their parent (the Enemy), you'll have to keep a reference to the Enemy inside the Collider scripts.