When I add “&& !hasPackage” to the first IF statement it stops destroying the packages when running over. Everything works fine if I remove that part. I have even tried “hasPackage = false”. Just tried with just “hasPackage”. It destroyed the package.
public class Delivery : MonoBehaviour
{
[SerializeField] bool hasPackage;
private void Start()
{
Debug.Log(hasPackage);
}
[SerializeField] float destroyDelay = 0.5f;
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Ouch!");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Package" && !hasPackage)
{
Debug.Log("Package picked up.");
hasPackage = true;
Debug.Log(hasPackage);
Destroy(other.gameObject, destroyDelay);
}
if (other.tag == "Customer" && hasPackage)
{
Debug.Log("Packaged delivered.");
hasPackage = false;
}
}
}