I’ve read similar threads to this, so I’m not coming in blind here
Here’s what I’m trying to do: I’m instantiating spheres… 63 of them in fact, from a Bubble Prefab which is just a primitive sphere with a Transparent/Diffuse material on it, and a few scripts to handle collisions / bonus score. The Prefab is also a kinematic rigidbody, if that helps…
In code, I instantiate the bubble, change the material’s color property based on a random number, and then the important part. I assign the transform’s parent to an empty GameObject with the CombineMesh script attached to it. I’m still getting 1 draw call per Prefab instantiated, which kills performance even before I draw my character!
Any help is appreciated.
Here’s the code:
var bubblePrefab : GameObject; //the prefab to spawn;
var timeDelay : float; //time in between instantiating bubbles;
var penaltyBubbleValue : int = -100000;
var maxRedBubbles : int = 8;
function Start()
{
var numRedBubbles : int = 0;
//+2x,-2z
for(var i=0;i<9;i++)
for(var j=0;j<7;j++)
{
var clone : GameObject = Instantiate(bubblePrefab, Vector3(bubblePrefab.transform.position.x+(2*i), bubblePrefab.transform.position.y, bubblePrefab.transform.position.z-(2*j)),Quaternion.identity);
clone.transform.parent = GameObject.Find("Bubbles").transform;
var MyBonusScore : BonusScore = clone.GetComponent(BonusScore);
var randomscore : float = Random.Range(1,15);
var myAudioCollision : AudioCollision = clone.GetComponent(AudioCollision);
if(randomscore <= 2 numRedBubbles < maxRedBubbles)//RED BUBBLE
{
MyBonusScore.bonusScore = penaltyBubbleValue;
clone.renderer.material.color = Color(.5,0,0,.5);
myAudioCollision.audioSourceObj = GameObject.Find("AudioSourceBubbleNegative");
numRedBubbles++;
}
else//GREEN BUBBLE
{
MyBonusScore.bonusScore = Mathf.RoundToInt(randomscore)*1000;
clone.renderer.material.color = Color(0,randomscore/10,0,.5);
myAudioCollision.audioSourceObj = GameObject.Find("AudioSourceBubblePop");
}
}
Destroy(this);
}