Kwang Won Choi
Kwang Won Choi

Reputation: 59

Unity - OnTriggerEnter is not being called

I'd like to make an aquarium where diverse fishes are existing.

I tried not to let fishes pass through cubes, but the OnTriggerEnter function doesn't work even if objects enter the trigger.

These pictures represent each of whale and cube inspector factors. whale inspector whale inspector

cube inspector

Upvotes: 0

Views: 13194

Answers (4)

Haluk Özgen
Haluk Özgen

Reputation: 31

I also want to add "Physics -> Auto Simulation = false" this will absolutely stop measurements.

Upvotes: 0

JoRouss
JoRouss

Reputation: 2884

You only need to add a Collider to your fish, (at the same level of the Flock script, or on a child GameObject).

OnTriggerEnter will only fire when a Collider enters a Trigger Collider

See MonoBehaviour.OnTriggerEnter(Collider)

Upvotes: 1

Ignacio Alorre
Ignacio Alorre

Reputation: 7615

I guess you are missing some of these things:

  • Add RigidBody to the fishes
  • Set the Collider of the GameObject that will detect the fishes as is trigger. And leave it unchecked in the Collider of the fishes

EDIT:

From your latest screenshot, your flock script that is supposed to detect the trigger is not attached to your GameObject. Simply attach it to one of the two GameObjects that is supposed to collide together.

Upvotes: 6

Game Code Edit
Game Code Edit

Reputation: 1

Ok so I've had this problem before. Something that helped me A LOT was to MAKE SURE YOU CREATE YOUR SCRIPT IN YOUR OBJECT. It's just easier.

If you didn't create your script IN your object then when you typing void OnTriggerEnter, there won't be any suggestion to finish the word 'OnTriggerEnter'. If you create it in the object than it should suggest to finish the word as 'OnTriggerEnter'.

Or you're just missing a collider or rigidbody. :)

Upvotes: 0

Related Questions