I have 100k cubes, I want to replace them on a 2D surfaces with a texture. The problem is that these surfaces should always be directed towards the camera. Please tell me how to do it.
My code that generates.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class World : MonoBehaviour
{
GameObject[] matrix;
int xSize = 100;
int ySize = 10;
int zSize = 100;
void Start()
{
matrix = new GameObject[xSize * ySize * zSize];
for (var x = 0f; x < xSize; ++x)
{
for (var y = 0f; y < ySize; ++y)
{
for (var z = 0f; z < zSize; ++z)
{
var i = (int)(x + y + z);
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(x * 4, y * 4, z * 4);
matrix[i] = cube;
}
}
}
}
void Update()
{
}
}
There is also a problem with a large generation time. For 1kk cubes it is about a minute.