Reputation: 47
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
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