ClinsBER
ClinsBER

Reputation: 47

How do I enable a component of a game object when the player collides with a trigger?

I am making a game where you have to get from point A to point B without hitting any obstacles. Some obstacles are moving and some are not. I decided to add a trigger in one of my levels that would enable two obstacles' scripts that would make them move. This is the script that is attached to the trigger:

 private void OnCollisionEnter(Collision collision)
{
    GameObject.Find("Obstacle (10)").GetComponent<MovingObjects>().enabled = true;
    GameObject.Find("Obstacle (9)").GetComponent<MovingObjects>().enabled = true;
}

For some reason, this code along with the method do not seem to work. Nothing happens when the player passes through the trigger. Why?

Upvotes: 0

Views: 160

Answers (1)

derHugo
derHugo

Reputation: 90813

Checkout the Collision matrix

Collision events (like OnCollisionEnter) are not thrown on a Collider marked as isTrigger.


Note that also afaik OnTriggerEnter would only be called on the object which is not the trigger.

Upvotes: 2

Related Questions