Where’s my error in my coding? I have looked over this for a while and can’t find one. It’s giving me the error:
“NullReferenceException: Object reference not set to an instance of an object
AlienMovment.Update () (at Assets/Scripts/AlienMovment.js:42)”
Here’s the code for AlienMovment{
if(transform.position.x > 25 || transform.position.x < -25){
//speed += .04;
speed *= -1.025;
for(var alien:GameObject in enemySettings.aliens){
alien.gameObject.transform.position.y -=1;
}
}
It’s giving me the error on the for loop.
Here’s the code for enemySettings{
function fillArray() {
aliens = GameObject.FindGameObjectsWithTag("Alien");
print(aliens.length);
}
function emptyArray(alien: GameObject) {
var AlienMovement: AlienMovment = alien.gameObject.GetComponent("AlienMovment");
print(AlienMovement.pointValue);
Score.score += AlienMovement.pointValue;
aliens.Clear();
Destroy(alien);
yield WaitForEndOfFrame;
fillArray();
}
Also, it’ll print the error the first time, but not the second unless an alien is destroyed. Any and all help would be amazing.