Hi everyone!:
I have a pattern “state” for AI behaviors.
In one of the scripts as part of the pattern “state” (call for example stateFollowTarget) I have placed the function OnCollisionEnter () to detect if it hits the target and pass a bomb in case there is a collision.
I’m surprised the OnCollisionEnter () function is not executed within that script and I don’t know why.
To check if the function was executed, I placed a Debug.Log(“Collision detectada”); But this message never appears on console even when a collision. It means that the function is not executed.
I tried to place the function (whithout changing the code that is inside), in the “main script” using the interface states and that it works. But not in the script that I need to works.
The script in which I need to work inherited from the interface AI_States
public class statePerseguirObjetivo : IA_State {…}
The first thing I think is that also inherits from MonoBehaviour as AI_State is an interface, not a class. But OnCollisionEnter () function does not run.
public class statePerseguirObjetivo : MonoBehaviour, IA_State {
…
void OnCollisionEnter(Collision col)
{
Debug.Log(“Collision detectada…”);
}
…
}
Anyone know why this happens? Anyone know how to fix it?
A greeting. Thanks foward.