Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Instantiate512Cubes : MonoBehaviour
  5. {
  6.     public GameObject cubePrefab;
  7.     GameObject[] cube = new GameObject[512];
  8.     public float maxScale;
  9.  
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         for (int i = 0; i < 512; i++)
  14.         {
  15.             GameObject instanceCube = (GameObject)Instantiate(cubePrefab);
  16.             instanceCube.transform.position = this.transform.position; //centering in object
  17.             instanceCube.transform.parent = this.transform;
  18.             instanceCube.name = "SampleCube" + i;
  19.             this.transform.eulerAngles = new Vector3(0, -0.703125f * i, 0);
  20.             instanceCube.transform.position = Vector3.forward * 100;
  21.             cube[i] = instanceCube;
  22.         }
  23.     }
  24.  
  25.     // Update is called once per frame
  26.     void Update()
  27.     {
  28.         for (int i = 0; i < 512; i++)
  29.         {
  30.             if (cube != null)
  31.             {
  32.                 cube[i].transform.localScale = new Vector3(10, (Audio.samples[i] * maxScale) + 2, 10);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement