As a classmate has stated, there is a problem with multiple collisions triggering multiple method calls. I’ve solved the problem with both the feet and body colliders adding to the score by putting a small check on it.
private void OnTriggerEnter2D(Collider2D collision)
{
if (!addedToScore)
{
addedToScore = true;
FindObjectOfType<GameSession>().AddToScore(pointsToAdd);
AudioSource.PlayClipAtPoint(coinPickupSFX, Camera.main.transform.position);
Destroy(gameObject);
}
}
I believe I’ve fixed the issue of the player hitting more than one collider and triggering more than one life lost as well.
private void Die()
{
if (myBodyCollider2D.IsTouchingLayers(LayerMask.GetMask("Enemy", "Hazards")))
{
myAnimator.SetTrigger("Dying");
GetComponent<Rigidbody2D>().velocity = deathKick;
if (isAlive) { FindObjectOfType<GameSession>().ProcessPlayerDeath(); }
isAlive = false;
}
}