I am creating a board game. I am instantiating pieces and triangles through code. My board consists of 90 moveable triangle spaces.
I am thinking spawning 90 triangles through code is inefficient. Right?
I would like to attach them to the board object. If I do that I don’t know how to manage those assets through code. Right now I have an array holding all the triangles in my board script, which seems to be some what efficient. My game manager script(attached to the camera) has easy access to all that data for raycasting and what-not. If I manually attach the triangles to the board, is there a simple way of managing all this data and making it accesible to other scripts?
What platform is this for? And are you only doing this once at level startup?
There’s lots of ways to pass data around and make game objects available to other game object; for example, you can acquire game objects in the scene by type, name, or tag, and then cache a reference to them for efficient access on a per-update basis.
What I did was make a “TriangleManager” object, that will hold a self-titled script. If I add triangle objects(90 of them) to the triangle manger object, I then would have to create an array of these objects in the triangle manager script for me to pass the data I need around freely. This is how I see it and it seems to be redundant. I would have 180 triangles, right?
var triManager : TriangleManager;
var triangle = new GameObject[90];
function StoreTriangleInfo()
{
triangle[0] = GameObject.Find("1");
}
Unless I’m misunderstanding what you mean, then no, it’s not redundant. You don’t have 180 triangles; you have 90 triangles with multiple references to each. Storing multiple references to single game objects is very common and isn’t at all redundant. (Again, assuming I’m understanding your question correctly.)