Code runs both if statements

Everytime I try driving over an object both messages print in the console. Both tags are confirmed to be on the right object and spelled correctly.

    void OnTriggerEnter2D(Collider2D other)
    {
            if (other.tag == "Package");
        {
            Debug.Log("Package Acquired");
        }

            if (other.tag == "Customer");
        {
        Debug.Log("Package Delivered Successfully");
        }
    }
}

Hi Kyle,

Welcome to our community! :slight_smile:

; marks the end of a command, even if it’s an “empty” command. Take a close look at your code and make sure the code blocks are defined correctly. Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

Did this help?


See also:

Yes, thanks! I removed the semi-colons from the ends of my if statements and now it works.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms