Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class AudioShowOutput : MonoBehaviour
- {
- [Header("Inputs")]
- public Transform[] objects;
- [Header("Pulsation info")]
- public Vector3 pulsateAxis;
- public float pulsationMagnitude = 1f;
- public float pulsationRoughness = 1f;
- private Vector3[] scales;
- private float[] samples;
- private AudioSource source;
- // Use this for initialization
- void Start ()
- {
- source = GetComponent<AudioSource> ();
- scales = new Vector3[objects.Length];
- samples = new float[256];
- for (var i = 0; i < objects.Length; i++)
- scales [i] = objects [i].localScale;
- }
- // Update is called once per frame
- void Update ()
- {
- source.GetOutputData (samples, 0);
- var vol = 0f;
- for (var i = 0; i < samples.Length; i++)
- vol += Mathf.Abs (samples [i]);
- for(var i = 0; i < objects.Length; i++)
- {
- var objToScale = objects [i];
- objToScale.localScale = Vector3.Lerp(objToScale.localScale, scales[i] + pulsateAxis * vol * pulsationMagnitude, Time.smoothDeltaTime * pulsationRoughness);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement