Hi there. I’m trying to have a trigger detect if a ball is in it’s trigger zone. The values don’t seem to be changing as they should accordingly. It is on UNET but only the local player needs to know if it is triggered or not. I mention that it’s on UNET just in case something related to it is causing the issue. If the issue doesn’t stem from UNET, I think it maybe that I’m not referencing the box collider properly. The trigger checkbox is checked on it. The way I’m doing it is having a script attached to the gameobject with the trigger collider, and then having my playercontroller script reference if it is triggered or not, then setting a float number to 1 if it is triggered, 0 if it’s not. I was trying to see if [Command] would work for the OnTriggerEnter() and OnTriggerExit() voids but I couldn’t get it working(I probably just coded it incorrectly if that is where it is going wrong).
Here’s the script that is attached to the object with the collider:
///////////////////////////////////////////
public static float Triggered;
void OnTriggerEnter(Collider Trigger)
{
if (Trigger.gameObject.CompareTag("Ball"))
{
Triggered = 1;
}
else
{
Triggered = 0;
}
}
void OnTriggerExit()
{
Triggered = 0;
}
///////////////////////////////////////////
Here’s the Reference to it in my playercontroller script:
//HitboxDetection
if (Hitbox.Triggered == 1)
{
IsTriggered = 1;
}
else if (Hitbox.Triggered == 0)
{
IsTriggered = 0;
}
if (IsTriggered == 1)
{
Debug.Log("CanPass");
}
Does anyone have an idea of what I’m doing wrong? Thanks in advance.
Comparing floats can be tricky so you should use a bool or int instead.
– Pengocat