No, it is a resource. I have that much working. It creates it without an array or for loop, but throws an error at me, if I do try to use an array or for loop regardless.
Use the correct type, rather than Object. Since your loop iterator is already an int, don’t cast to int. Just Squad[men]. And yes, start at 0, not 1.
Yeah, I know about 0. I just set it to 1 to see if it would fix the problem. Was a shot in the dark I admit.
I changed the Object[ ] squad to GameObject[ ] squad but I still have issues because it traces back to before with Resources.Load(“soldier”) as GameObject in SpawnSoldier();
Object SpawnSoldier()
{
GameObject soldier = Instantiate (Resources.Load("soldier") as GameObject, this.transform.position + new Vector3(0,0,2), new Quaternion(0,0,0,0) );
return soldier;
}
It gives me an error of; Cannot implicitly convert type UnityEngine.Object to UnityEngine.GameObject . Any ideas?
Soldier is a prefab by the way if you are wondering.
I also know that it is specific to the array, as without trying to assign values to indexes in the array within the for loop, it runs fine and does not throw me an error.
Also, it would be better to create a variable and only call Resources.Load(“soldier”) once, set the variable equal to it, then make your SpawnSoldier function instantiate the variable instead of instantiating (Resources.load), cause Resources.Load is relatively slow/expensive and its better to create references first.