Search Unity

[SOLVED]Physics.OverlapSphere not working

Discussion in 'Physics' started by DaresFireson, Apr 24, 2019.

  1. DaresFireson

    DaresFireson

    Joined:
    Jan 10, 2017
    Posts:
    61
    I have the following code:
    Code (CSharp):
    1. private IEnumerator SpellDOT()
    2.     {
    3.         Collider[] colliders = Physics.OverlapSphere(thisSpellTarget.transform.position, spellDamageRadius);
    4.  
    5.         foreach (Collider collider in colliders)
    6.         {
    7.             if (collider.tag == "Enemy")
    8.             {
    9.                 //Debug.Log(targetEnemy);
    10.                 //Debug.Log(spellDamageOverTime * Time.deltaTime);
    11.                 targetEnemy.TakeDamage(spellDamageOverTime);
    12.             }
    13.         }
    14.  
    15.         yield return new WaitForSeconds(3f);
    16.     }
    It seems only one enemy get damaged at the edge of the sphere. Also the
    Code (CSharp):
    1. spellDamageOverTime * Time.deltaTime
    return a small value like 6.1 when
    Code (CSharp):
    1. spellOverTime = 500
     
  2. DaresFireson

    DaresFireson

    Joined:
    Jan 10, 2017
    Posts:
    61
    I had to add
    Code (CSharp):
    1. targetEnemy = collider.GetComponent<Enemy>();
    inside the if statement.