How to hit enemies with a scream

Hi people. I’m making a 2d game for android using sprite manager. In the game the player has to scream in order to kill enemies. I was wondering if somenone could give me an advice on the best way to do this. (i’m new to unity and was following tutorials and books up until now. I thought at first that i could test collision with a scream sprite, but i’m having difficulties figuring out where in the hierarchy the scream would be and where i would insert the script.)

“For something like this, you’d test for proximity, and then maybe add some kind of distance falloff (depending on what the scream is supposed to be). I wouldn’t be using collisions for this kind of thing.”

or

“put a collider on an empty gameobject, then instantiate it when the player screams and put code to make it move in function Start()” but “If you were going to do that, you’d be better to use Physics.CheckSphere instead.”

Answer the question guys.

Ok, fine, since there seems to be some call for detailed answers here-

To check for objects in a proximity, use Physics.OverlapSphere to get an array of colliders which are in range.

First off, make all the enemies which can be affected by this scream attack are on a layer together, so that your OverlapSphere will only return those which can be hit by it.

Then, use

foreach(Collider hit in Physics.OverlapSphere(screamOrigin.position, screamRadius, screamLayers)
{
    float damagePercentage = Vector3.Distance(screamOrigin.position, hit.transform.position) / screamRadius;
    hit.SendMessage("ScreamDamage", damage * damagePercentage);
}

Then, on each object that can be hit by the scream attack, implement a function with these characteristics-

void ScreamDamage(float damage)
{
    // deal damage to the object
}