Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawCubes : MonoBehaviour {
- public Mesh cube;
- public int submeshIndex; //If the mesh has more than one submesh, specify which one to draw. Normally this can be left as 0.
- public Material material; //Note: This material must have instancing enabled.
- private Matrix4x4[] locations;
- void Start() {
- locations = new Matrix4x4[10];
- for (int i = 0; i < locations.length; ++i) {
- //Position at (i,0,0), no rotation, with no scaling
- locations[i] = Matrix4x4.TRS(new Vector3(i,0,0), Quaternion.identity, Vector3.one);
- }
- }
- void Update() {
- Graphics.DrawMeshInstanced(cube, submeshIndex, material, matrices);
- }
- }
Add Comment
Please, Sign In to add comment