Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class AudioShowOutput : MonoBehaviour
  5. {
  6. [Header("Inputs")]
  7. public Transform[] objects;
  8.  
  9. [Header("Pulsation info")]
  10. public Vector3 pulsateAxis;
  11. public float pulsationMagnitude = 1f;
  12. public float pulsationRoughness = 1f;
  13.  
  14. private Vector3[] scales;
  15. private float[] samples;
  16. private AudioSource source;
  17.  
  18. // Use this for initialization
  19. void Start ()
  20. {
  21. source = GetComponent<AudioSource> ();
  22.  
  23. scales = new Vector3[objects.Length];
  24. samples = new float[256];
  25.  
  26. for (var i = 0; i < objects.Length; i++)
  27. scales [i] = objects [i].localScale;
  28. }
  29.  
  30. // Update is called once per frame
  31. void Update ()
  32. {
  33. source.GetOutputData (samples, 0);
  34.  
  35. var vol = 0f;
  36.  
  37. for (var i = 0; i < samples.Length; i++)
  38. vol += Mathf.Abs (samples [i]);
  39.  
  40.  
  41. for(var i = 0; i < objects.Length; i++)
  42. {
  43. var objToScale = objects [i];
  44.  
  45. objToScale.localScale = Vector3.Lerp(objToScale.localScale, scales[i] + pulsateAxis * vol * pulsationMagnitude, Time.smoothDeltaTime * pulsationRoughness);
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement