I have three sets of 50x50 layers of cubes. Unity is amazing for being able to render 7500 cubes. But, I want to know if I can improve performance at all. It’s ok when I look away from the cubes, but on the bottom layer, when I’m looking up, I get about 15 FPS. Can anyone help?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public Vector2 groundSize;
public GameObject cube;
public Text text;
[Range(0, 99)]
public int scale;
void Start () {
generateGround(0);
generateGround(-5);
generateGround(-10);
}
void generateGround(int baseHeight)
{
for (int x = 0; x < groundSize.x; x ++)
{
for (int y = 0; y < groundSize.y; y ++)
{
GameObject newCube = Instantiate(cube, new Vector3(-groundSize.x / 2 + 0.5f + x, baseHeight, -groundSize.y / 2 + 0.5f + y), Quaternion.Euler(Vector3.zero)) as GameObject;
newCube.transform.localScale = Vector3.one * scale / 100;
newCube.transform.name = "newCube";
newCube.GetComponent<Renderer>().material.color = new Color(Random.value, Random.value, Random.value);
}
}
}
Thanks.