I am working on a projectile manager for my 2D space shooter iPhone game. And im trying at the start off the level make a array with all the ProjectileController script that is attached to the projectile gameobjects. But i get a NullReferenceException error on the line in the second for loop. How can i make this function work? Or is there a better way of achiving what im trying to do?
private var maxNumProjectiles : int = 100;
private var projectilesArray : ProjectileController[];
function InitializeProjectiles() // Initializes all the projectiles and adds their ProjectileController script to the projectilesArray
{
for(i=0; i<maxNumProjectiles; i++)
{
var clone : GameObject;
clone = Instantiate(projectilePrefab, projectileIntPosition, Quaternion.identity);
}
var tempArray : GameObject[] = GameObject.FindGameObjectsWithTag("Projectile");
for(i=0; i<maxNumProjectiles; i++)
{
projectilesArray _= tempArray*.GetComponent("ProjectileController");*_
_*}*_
_*}*_
_*```*_