I have this code:
private Enemy targetEnemy;
private string enemyTag = "Enemy";
public int spellDamageOverTime = 500;
public int spellDamageRadius = 20;
[HideInInspector]
public Transform thisSpellTarget;
public GameObject spellTarget;
void Update ()
{
if(thisSpellTarget != null)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
thisSpellTarget.transform.position = hitInfo.point;
}
GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
foreach (GameObject enemy in enemies)
{
targetEnemy = enemy.GetComponent<Enemy>();
}
}
if (Input.GetMouseButtonDown(0) && thisSpellTarget != null)
{
//Debug.Log("Mouse clicked");
Destroy(thisSpellTarget.gameObject);
StartCoroutine(SpellDOT());
}
}
public void SpellButtonAction()
{
thisSpellTarget = ((GameObject)Instantiate(spellTarget)).transform;
}
private IEnumerator SpellDOT()
{
Collider[] colliders = Physics.OverlapSphere(thisSpellTarget.transform.position, spellDamageRadius);
foreach (Collider collider in colliders)
{
if (collider.tag == "Enemy")
{
//Debug.Log(targetEnemy);
//Debug.Log(spellDamageOverTime * Time.deltaTime);
targetEnemy.TakeDamage(spellDamageOverTime);
}
}
yield return new WaitForSeconds(3f);
}
It only damage 1 enemy at the margin of the sphere and ignore the others. Also
spellDamageOverTime * Time.deltaTime
return 6.1