OnTriggerEnter2D problem

If just one of these if statements launches all the rest launch too, can someone help me?

void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log(other.gameObject.name);
        if(other.gameObject.name == "X_Middle");
        {
            x_middle.enabled = true;
        }

        if(other.gameObject.name == "X (Bottom - Middle)");
        {
            x_bottom_middle.enabled = true;
        }

        if(other.gameObject.name == "X (Upper - Middle)");
        {
            x_upper_middle.enabled = true;
        }

        if(other.gameObject.name == "X (Right - Middle)");
        {
            x_right_middle.enabled = true;
        }

        if(other.gameObject.name == "X (Left - Middle)");
        {
            x_left_middle.enabled = true;
        }

        if(other.gameObject.name == "X (Top RIght Upper Corner)");
        {
            x_top_right_upper_corner.enabled = true;
        }

        if(other.gameObject.name == "X (Top Right Bottom Corner)");
        {
            x_top_right_bottom_corner.enabled = true;
        }

        if(other.gameObject.name == "X (Top Left Bottom Corner)");
        {
            x_top_left_bottom_corner.enabled = true;
        }

        if(other.gameObject.name == "X (Top Left Upper Corner)");
        {
            x_top_left_upper_corner.enabled = true;
        }
    }

Hey @LittleSnipe,

You need to remove the semicolon (;) at the end of each of the if statements. If that doesn’t make things work like you want, try also using else if instead of if for the other statements.

It should maybe look something like this:

 void OnTriggerEnter2D(Collider2D other)
     {
         Debug.Log(other.gameObject.name);
         if(other.gameObject.name == "X_Middle")
         {
             x_middle.enabled = true;
         }
 
         else if(other.gameObject.name == "X (Bottom - Middle)")
         {
             x_bottom_middle.enabled = true;
         }
...

See the C# docs for more info on working with if statements: if and switch statements - select a code path to execute | Microsoft Learn

Hope that helps!