Omitted Destroy

Hello. I have a weird problem. The following code does successfully resolve every time except the very last iteration when “remainingCost” reaches 0 during the resolution.

Debug.Log, “remainingCost–” and CheckBuilt(); are resolved in this weird iteration.
Object.Destroy and orders = idle doesn’t, however.

Can you think of any reason that may be behind this?

private void OnTriggerEnter(Collider collision)
{ if (collision.gameObject.transform.tag == "Worker" && 
collision.gameObject.GetComponent<PlayerClass>().carriedMaterial != null 
&& gameObject.GetComponent<Building>().remainingCost > 0)
{
Debug.Log("run");
Object.Destroy(collision.gameObject.GetComponent<PlayerClass>().carriedMaterial);
remainingCost--;
collision.gameObject.GetComponent<PlayerClass>().orders = PlayerClass.OrderTypes.Idle;
CheckBuilt();
} }

Thank you very much!

On line 4, change

gameObject.GetComponent<Building>().remainingCost > 0

to

gameObject.GetComponent<Building>().remainingCost >= 0

that may work