So I’ve looked around but haven’t found an answer I could use so I’ll ask my question. In my code I procedurally create a series of object using one prefab. For this to work I create at least 1000 of these meshes with no texture (just a base color) depending on what I want to see. But with an average of create 5000 gameobjects in the start of the game creates not only a foreseeable mini-freeze at the beginning but on older computers gives me a fps of at most 10. I have to make the gameobjects at start up being it’s so efficient as the developer but I was wondering how I could combine the meshes of the objects. Here’s part of the code that creates the objects:
var numberOfSegments = 0;
var tubeLength = 0;
var baseTubeObject : GameObject;
var blockerPrefab : GameObject;
var jumpSeg = 150;
function Start () {
for(i = 0; i < numberOfSegments + 1; i++) {
var segGroup = new GameObject();
segGroup.name = "Segment"+i;
segGroup.transform.position = Vector3(0,0,0);
var groupColor = Color(Random.Range(0.0,1.0),Random.Range(0.0,1.0), Random.Range(0.0,1.0));
if(i == numberOfSegments) {
groupColor = Color(.05,.05,.05);
} else if(i + 1 == numberOfSegments) {
groupColor = Color(.95,.95,.95);
}
for(c = 0; c < tubeLength; c += 2) {
var myPosition = Mathf.Max((i - 1), 0) * tubeLength + c;
if(i != 0)
myPosition += jumpSeg;
var tubeObject = Instantiate(baseTubeObject, Vector3(myPosition,0,0), Quaternion.Euler(0,0,0));
tubeObject.transform.localScale = Vector3(1.9,6,6);
tubeObject.renderer.material.color = groupColor;
tubeObject.transform.parent = segGroup.transform;
tubeObject.gameObject.name = "Wall";
if(i == 0 && c == jumpSeg)
break;
....
I want to combine the meshes of the second loop so each of 'segGroup’s children have one mesh. What would the easiest way to do this be?