Skip to content

Instantly share code, notes, and snippets.

@dilanshah
Created March 1, 2018 00:03
Show Gist options
  • Save dilanshah/e59537685e024f8e55b4ed3a5d2d5ce6 to your computer and use it in GitHub Desktop.
Save dilanshah/e59537685e024f8e55b4ed3a5d2d5ce6 to your computer and use it in GitHub Desktop.
This script places parametric cubes in a ring around a user wearing an HMD Audio Visualizer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Instantiate512Cubes : MonoBehaviour {
public GameObject _sampleCubePrefab;
private GameObject[] _sampleCube = new GameObject[512];
public float _maxScale;
void Start () {
// Use this for initialization
for (int i = 0; i < 512; i++)
{
GameObject _instanceSampleCube = (GameObject)Instantiate (_sampleCubePrefab);
_instanceSampleCube.transform.position = this.transform.position;
_instanceSampleCube.transform.parent = this.transform;
// gives each cube a unique name
_instanceSampleCube.name = "SampleCube" + i;
// the offset needed to produce the ring of parametrics cubes
this.transform.eulerAngles = new Vector3 (0.0f, -0.703125f * i, 0.0f);
// place each instance in a certain distance shorthand for writing Vector3(0, 0, 1).
_instanceSampleCube.transform.position = Vector3.forward * 100;
_sampleCube [i] = _instanceSampleCube;
}
}
// Update is called once per frame
void Update () {
for (int i = 0; i < 512; i++)
{
if (_sampleCube != null) {
// grab scale relative to the parent
_sampleCube[i].transform.localScale = new Vector3(10, (AudioPeer._samples[i] * _maxScale) + 2, 10);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment