My game objects keeps on getting destroyed even if i dont want them to,Destroying some particular objects but it destroys my customer too

hey i am making a delivery game in which i have to pick up package and deliver. I0t works fine when i pick them up they disappear but when i run over on customer, customer disappears aswell. Here is my C# script please help me out.

Look at your if statement, your code is not inside the braces. You currently check if the other has the tag “Package” and that you don’t have package. But you don’t do anything if that condition is true, no matter what happens you run the code under it. You should write the code that happens if the condition is met inside the braces. So it should be:

 private void OnTriggerEnter2D(Collider2D other)
 {
     if(other.tag == "Package" && !hasPackage) 
     {
         //code for destroying and such here
     }
 }

You have the same issue with the if statement below, you check a condition and then you run the code in the braces. But there is nothing in the braces. Then you create a new scope with the braces, the code inside of that scope will also be run every time. It should be:

if (other.tag == "Customer" && hasPackage) 
{
    //code for dealing with package delivered here
}