This question was
closed Dec 16, 2016 at 03:17 PM by
Vylax for the following reason:
The question is answered, right answer was accepted
Question by
Vylax · Dec 16, 2016 at 03:01 PM ·
gameobjecterror messagearray of gameobjectsarraylist
BCE0019: 'gameObject' is not a member of 'Object'.
Searched in sames question but didn't found my case... here's the code:
var closeEnemies : Array = new Array();
//...
for(var i : int = 0; i < closeEnemies.length + 1; i++) {
if(closeEnemies[i] != null) {
closeEnemies[i].gameObject.GetComponent(enemy).health -= damage;
}else{
i++;
}
}
//...
function OnCollisionEnter2D (other : Collision2D) {
if(other.gameObject.GetComponent(friendly).status == "Enemy" && ownCase.GetComponent(Case).empty == false) {
y += 1;
other.gameObject.GetComponent(numbers).x = y;
closeEnemies[other.gameObject.GetComponent(numbers).x] = other.gameObject;
}
}
function OnCollisionExit2D (other : Collision2D) {
if(other.gameObject.GetComponent(friendly).status == "Enemy" && ownCase.GetComponent(Case).empty == false) {
closeEnemies[other.gameObject.GetComponent(numbers).x] = null;
}
}
As you can see closeEnemies is an Array wich I stock colliding gameObjects in.
I tried a lot of things but I still get BCE0019: 'gameObject' is not a member of 'Object'. error...
What's wrong with the script ?
Thx for your help.
Comment
Best Answer
Answer by tanoshimi · Dec 16, 2016 at 03:09 PM
This line right at the top:
var closeEnemies : Array = new Array();
You don't specify what closeEnemies is an array of. So its elements are all just generic "Objects". And as the error messages states, objects don't have a .gameObject property.
I don't use Javascript, but I assume you meant something like:
var closeEnemies : GameObject[];