OnGUI() works in editor, but not in build with an odd twist!

I have a ship moving, that checks for collision as well as trigger. When ship collides with another ship it gives a collision status message.

I have another object that has checks for trigger.

In Editor
My onGUI() function works perfectly for both collision as well as trigger

In Build
OnCollisionEnter() and OnCollisionExit() works against another ship which detects collision and not trigger.

OnTriggerEnter() and OnTriggerExit() DOES NOT WORK which means

GUI.Box(new Rect(winX, winY, 200, 100), content); doesn’t show up with my status messages.

public class OnDriftingCourse : MonoBehaviour
{
    public Boolean collided = false;
    GUIContent content;
    public Texture BoxTexture;
    public int winW = 200;
    public int winH = 100;
    private int winX;
    private int winY;

   


    void OnTriggerExit(Collider c)
    {
        collided = true;
        content = new GUIContent(" Trigger Exited " , BoxTexture, "--");
        print("ON Trigger Exit");
    }

    void OnCollisionEnter(Collision collision)
    {
        collided = true;
        content = new GUIContent(" Collided enter ", BoxTexture, "--");
        print("ON Colission Enter");
    }

    void OnCollisionExit(Collision collision)
    {
        collided = false;
        //content = new GUIContent(" Collided enter ", BoxTexture, "--");
        //print("ON Colission Enter");
    }


    void OnTriggerEnter(Collider c)
    {
        collided = true;
        content = new GUIContent(" Trigger ENTER ", BoxTexture, "--");
        print("ON Trigger Enter");

    }


    void OnGUI()
    {
        winX = (Screen.currentResolution.width) / 2;
        winY = (Screen.currentResolution.height) / 2;

        winX = 600; winY = 50;
        if (collided)
        {
            GUI.Box(new Rect(winX, winY, 200, 100), content);
        }
        else
        {
            collided = false;
        }
            

    }
}

Hi @prakashxavier

Could it be that perhaps you are setting collided to true when it should be false in OnTriggerExit?

     void OnTriggerExit(Collider c)
     {
         collided = true; // should this be false instead?
         content = new GUIContent(" Trigger Exited " , BoxTexture, "--");
         print("ON Trigger Exit");
     }

Also do these colliders overlap each other in a weird way somehow?

Thanks for your reply Steen

collided = true is only a flag that I use to trigger my GUI box.

the colliders dont overlap i’ve seperated them.

The issue really seems to be that it works differently in build and different in editor. Works just fine in editor.

Got it to work after I downloaded the latest version of Unity!