I am a bit confused with how i set up my scene to do this. I want to create an array of my class System. Of which contains a Vector3 position a reference to a sprite renderer and the game object. I also instantiate the game object in that position in my array creation.
I setup my array like this in an empty game object in my game world:
public System[] systemArray;
void Start () {
systemArray = new System[totalSystems];
for (int i = 0; i < totalSystems; i++)
{
systemArray[i].worldPos = new Vector3(Random.Range(min,max),Random.Range(min,max), Random.Range(minZ,maxZ));
Instantiate(systemObject,systemArray[i].worldPos,Quaternion.identity);
}
}
Now my System script is not attached to a game object it is just a script that will store the data of the instantiated game objects i just made. And the code looks like this:
public class System : MonoBehaviour {
public SpriteRenderer spriteRenderer;
public GameObject gameObject;
public Vector3 worldPos;
}
My confusion here is how do i link this all up.
The goal here is i will want to be able to destroy the game objects from the scene but i will still be able to access their Vector3, the GO and sprite renderer from System so i can re-instantiate again.
I got myself really confused so am hoping for some help on how i am suppose to set this up efficiently.
System. That is a top level .net namespace. Something likeGameSystemwould be better and not so easy confusable. - Gunnar B.