- Home /
Question by
primus88 · Jun 01, 2013 at 05:54 PM ·
scripting problemspellsaoe
What is wrong in this AOE damage script
public void AOE()
{
if (hit.collider.tag == "RayEnemy" & dealhealing==true & isaoe==true){
var bounds = hit.collider.bounds;
var v3 = bounds.center;
v3.y -= bounds.extents.y;
damagePrefab = Instantiate(particle, v3, transform.rotation) as GameObject;
GameObject[] enemies = GameObject.FindGameObjectsWithTag("character");
foreach(GameObject enemy in enemies) {
if(blastRadius >= Vector3.Distance(v3, enemy.position)) {
health emm3=(health)enemy.GetComponent("health");
if(emm3){
emm3.currenthealth=emm3.currenthealth-spellDamage;
MenuController.mana=MenuController.mana-spellcost;
dealdamage=false;
spells.menuactive=true;
MenuController.isHidden=false;
}
}
}
}
}
The error I receive is :
Type UnityEngine.GameObject' does not contain a definition for
position' and no extension method position' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
And : Argument #2' cannot convert
object' expression to type `UnityEngine.Vector3'
Thanks
Comment
Best Answer
Answer by hiddenspring81 · Jun 01, 2013 at 06:23 PM
Try changing it to
if(blastRadius >= Vector3.Distance(v3, enemy.transform.position))
The problem is that enemy
is a GameObject
, and you're trying to access position
, which is only available on the object's transform
.