I found out that the problem is I'm not referencing it correctly.
Trigger on player controller prefab not working?
I have a playercontroller prefab that get's spawned in by my network manager when a player joins a server. It has a trigger that is attached to it as a child, but it only seems to only work as soon as the player spawns then doesn't work after that. I know it has to do with the fact that it's on the prefab. I put the script on a trigger that is in my scene and it worked fine. I need the trigger on the player prefab to be able to constantly tell if an object with the tag "ball" is in it's triggerzone. Does anyone have an idea how to get it working? Thanks in advance.
Here's the code I have for the trigger:
///////////////////////////////////////////
public static int Triggered;
void OnTriggerEnter(Collider Trigger)
{
Debug.Log("TriggerDetectsObject");
if (Trigger.gameObject.CompareTag("Ball"))
{
Debug.Log("TriggerDetectsBall");
Triggered = 1;
}
else
{
Triggered = 0;
}
}
void OnTriggerExit()
{
Triggered = 0;
}
///////////////////////////////////////////
Is it the problem of the static keyword you added for your "Triggered" variable. Because it will be common for all the objects having this script.
No. The debug.logs only show up right at the start if something is colliding with it, then don't work at all afterwards. So that tells me it's the ontriggerenter and exit voids where the problem is occurring.
You need to change :
OnTriggerExit ( )
To :
OnTriggerExit(Collider other)
As per the documentation OnTriggerExit takes an argument.