private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Jam") || collision.CompareTag("Dispensed")) { //Destroy(collision.gameObject); GameManager.instance.IncreaseJamWasted(); collision.gameObject.transform.SetParent(transform); if (GameManager.instance.GetJamWasted() == 100) { lifeManager.LoseLife(); animator.SetTrigger("Angry"); boss.PlayAngrySounds(); notificationManager.UpdateNotificationText("-1 Life! Stop wasting Jam!"); foreach (Transform t in collision.transform.parent.transform) { if (t.CompareTag("Jam") || t.CompareTag("Dispensed")) { Destroy(t.gameObject); } } //prompt the user telling them what they did wrong } } }
private void OnTriggerEnter2D(Collider2D collision) { Destroy(collision.gameObject); //if we are destroying a jar, check if we lose a life if (collision.GetComponent <Jar>()) { //Debug.Log("Jar had " + collision.transform.childCount + " children"); collision.GetComponent <Jar>().CalculateJamProportion(); //check how full the jar is if (collision.transform.childCount < (jarFull * 0.75f)) { lifeManager.LoseLife(); animator.SetTrigger("Angry"); notificationManager.UpdateNotificationText("-1 Life! We can't sell a jar with no jam in it!"); boss.PlayAngrySounds(); } //if most of the jam is the correct type else if (collision.gameObject.GetComponent <Jar>().CalculateJamProportion() < 0.75f) { lifeManager.LoseLife(); animator.SetTrigger("Angry"); notificationManager.UpdateNotificationText("-1 Life! It's not hard to fill a jar with the right kind of jam!"); boss.PlayAngrySounds(); } //if the jar doesn't have a lid else if (collision.gameObject.transform.GetChild(3).gameObject.activeSelf == false) { lifeManager.LoseLife(); animator.SetTrigger("Angry"); notificationManager.UpdateNotificationText("-1 Life! Jam is getting everywhere! Put a lid on it!"); boss.PlayAngrySounds(); } else { animator.SetTrigger("Happy"); PointManager.instance.IncreasePoints(); boss.PlayHappySounds(); } } }