Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class DrawCubes : MonoBehaviour {
  2. public Mesh cube;
  3. public int submeshIndex; //If the mesh has more than one submesh, specify which one to draw. Normally this can be left as 0.
  4. public Material material; //Note: This material must have instancing enabled.
  5.  
  6. private Matrix4x4[] locations;
  7. void Start() {
  8. locations = new Matrix4x4[10];
  9. for (int i = 0; i < locations.length; ++i) {
  10. //Position at (i,0,0), no rotation, with no scaling
  11. locations[i] = Matrix4x4.TRS(new Vector3(i,0,0), Quaternion.identity, Vector3.one);
  12. }
  13. }
  14. void Update() {
  15. Graphics.DrawMeshInstanced(cube, submeshIndex, material, matrices);
  16. }
  17. }
Add Comment
Please, Sign In to add comment