My approach on this challenge

private void OnParticleCollision(GameObject other) {
        if(hitPoints > damage) {
            score.UpdateScore(amountToAdd);
            hitPoints -= 20;
        }
        if(hitPoints <= damage) {
            score.UpdateScore(amountToAddWhenKilled);
            GameObject vfx = Instantiate(deathVFX, transform.position, Quaternion.identity);
            vfx.transform.parent = parent;
            Destroy(gameObject);
        }
    }
1 Like

Does it work like you intended?

it does :smiley:

Why do you subtract 20 from the hitPoints? You wouldn’t have to subtract the variable “damage” from the hitPoints, because otherwise you would have hardcoded the value?

Privacy & Terms