H
H
Herman Coffman2018-10-25 18:16:28
C++ / C#
Herman Coffman, 2018-10-25 18:16:28

How to make the OnTrigerEnter function work only when touched with 1 object?

How to make the OnTrigerEnter function work only when touched with 1 object? There is an object (hedgehog) that should remove the player (I did this) and there is a wall that adds a point when touched, but when the player touches the wall it is also removed. How to make the wall not delete the player, that is, OnTrigerEnter only works for the hedgehog. (Player, hedgehog and wall have RigidBody and BoxCollider, hedgehog and wall with trigger).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2018-10-25
@Gera01

If you strictly answer your question, then in the physics settings you can set which layer can interact with which. But the hedgehog will walk through the walls.

G
GavriKos, 2018-10-25
@GavriKos

The correct option is not to delete the wall (the wall doesn’t care who hit it), but the object itself that hit it should catch Ontriggerenter and decide whether to delete it or not (there is a delete script on the hedgehog, not on other objects).
Wrong, but working option - the wall checks what kind of object collided and decides to delete it or not. You can check by:
- ​​name (terrible)
- script presence (medium)
- tag (normal).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question