finally finished working out the scripts for my fireball (rpg video 177) but the DealAreaDamage() keeps throwing a null reference. can someone help me by figuring out where my mistake is please!
private void DealAreaDamage()
{
// TODO add method to choose a number of random targets up to the numberOfTargets
foreach(Health target in GetTargets())
{
Vector3 pos1 = transform.position;
Vector3 pos2 = target.transform.position;
int damageModifier = 1 - (int)Vector3.Distance(pos1, pos2);
target.TakeDamage(damage);
}
}
private Health[] GetTargets()
{
Health[] targets = new Health[100];
int arrayIndex = 0;
damageEffect.Play();
foreach (Health candidate in FindObjectsOfType<Health>())
{
float rangeToTarget = Vector3.Distance(candidate.transform.position, transform.position);
if (rangeToTarget <= areaOfEffct) { targets[arrayIndex] = candidate; }
arrayIndex++;
if (arrayIndex > targets.Length) { break; }
}
return targets;
}