The question is answered, right answer was accepted
OnTriggerEnter work only once
Hello everyone, I'm using unity since a week and i get a problem with my trigger.
Resume : I make a runner where the main corridor is divided in 3 section. I have an IA that will spawn in front of the player sometime. The IA will run in front of the player and have to dodge obstacles.
To do the dodging system i have created 3 capsules in from of my IA and check il the capsule collide with an obstacle.
The result is pretty great so far, but my fonction "OnTriggerEnter" is workiing only once and i dont know why.
Exemple ; The first obstacle is on the A and B line, The function return A , B (when the trigger enter on collision with an obstacle) and, "A passe faux", "B passe faux". (when the trigger exit the obstacle.
But is then il there is another obstacle on the A and B section, the trigger will not detect the collision.
Could you help me please ? :) Here is my code Ps : The code is component of each capsule
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class detect_col_poulet : MonoBehaviour { public bool capsuleA = false; public bool capsuleB = false; public bool capsuleC = false;
void OnTriggerEnter(Collider col)
{
if (gameObject.name == "capsuleA")
{
capsuleA = true;
Debug.Log ("A");
}
if (gameObject.name == "capsuleB")
{
capsuleB = true;
Debug.Log ("B");
}
if (gameObject.name == "capsuleC")
{
capsuleC = true;
Debug.Log ("C");
}
}
void OnTriggerExit(Collider col)
{
if (gameObject.name == "capsuleA")
{
capsuleA = false;
Debug.Log ("A passe faux");
}
if (gameObject.name == "capsuleB")
{
capsuleB = false;
Debug.Log ("B passe faux");
}
if (gameObject.name == "capsuleC")
{
capsuleC = false;
Debug.Log ("C passe faux");
}
}
}
the code is fine. either any of the colliders involved in the second and consecutive events are different from the first, or the collider moving is moved wrong. I guess the former is the case. pause the game and check prior to collision if everything is setup right
Yeah i'd just figured out that my problem was from my other script (the one that make move my IA) and not from my collider check script. Sorry for being that stupid ^^"
Follow this Question
Related Questions
Destroy object on hover? 1 Answer
Moving an Object Using a Trigger 0 Answers
Collider dosent detect trigger 0 Answers
OnTriggerEnter Issue - Collider problem 0 Answers