Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 08, 2015 at 11:48 PM by KnightRiderGuy for the following reason:

Found a solution

avatar image
0
Question by KnightRiderGuy · Feb 26, 2015 at 06:31 PM · audiosourcelinerenderereffectsvisualization

Line Renderer Music Visualizer Not Working

OK This is probably something simple that I am missing but I am just not seeing please help if you can. My audio clip plays fine when activated but my line renderer audio visualizer only seems to work if I assign a sound clip directly to the audio source, it seems to be ignoring my audio clips in my array??? Please help :) Here is my entire script. I shave also attached a screen capture to also help with understanding :)alt text

 using UnityEngine;
 using System.Collections;
 
 public class VBtestAudioVisualizer : MonoBehaviour
 {
     //Audio Clip Selections
     public AudioClip VoiceClip01;
     public AudioClip VoiceClip02;
     public AudioClip VoiceClip03;
     public AudioClip VoiceClip04;
 
 
     //An AudioSource object so the music can be played
     public AudioSource aSource;
     //A float array that stores the audio samples
     public float[] samples = new float[64];
     //A renderer that will draw a line at the screen
     public LineRenderer lRenderer;
     //A reference to the cube prefab
     public GameObject cube;
     //The transform attached to this game object
     public Transform goTransform;
     //The position of the current cube. Will also be the position of each point of the line.
     private Vector3 cubePos;
     //An array that stores the Transforms of all instantiated cubes
     private Transform[] cubesTransform;
     //The velocity that the cubes will drop
     private Vector3 gravity = new Vector3(0.0f,5.0f,0.0f);
     
     void Start()
     {
         //The line should have the same number of points as the number of samples
         lRenderer.SetVertexCount(samples.Length);
         //The cubesTransform array should be initialized with the same length as the samples array
         cubesTransform = new Transform[samples.Length];
         //Center the audio visualization line at the X axis, according to the samples array length
         goTransform.position = new Vector3(-samples.Length/2,goTransform.position.y,goTransform.position.z);
         
         //Create a temporary GameObject, that will serve as a reference to the most recent cloned cube
         GameObject tempCube;
         
         //For each sample
         for(int i=0; i<samples.Length-1;i++)
         {
             //Instantiate a cube placing it at the right side of the previous one
             tempCube = (GameObject) Instantiate(cube, new Vector3(goTransform.position.x + i, goTransform.position.y, goTransform.position.z),Quaternion.identity);
             //Get the recently instantiated cube Transform component
             cubesTransform[i] = tempCube.GetComponent<Transform>();
             //Make the cube a child of this game object
             cubesTransform[i].parent = goTransform;
         }
     }
     
     void Update () 
     {
         //Obtain the samples from the frequency bands of the attached AudioSource
         aSource.GetSpectrumData(this.samples,0,FFTWindow.BlackmanHarris);
         
         // For each sample
         for(int i=0; i<samples.Length-1;i++)
         {
             cubePos.Set(cubesTransform[i].position.x, Mathf.Clamp(samples[i]*(i*i),0,50), cubesTransform[i].position.z);
             
             //If the new cubePos.y is greater than the current cube position
             if(cubePos.y >= cubesTransform[i].position.y)
             {
                 //Set the cube to the new Y position
                 cubesTransform[i].position = cubePos;
             }
             else
             {
                 //The spectrum line is below the cube, make it fall
                 //                cubesTransform[i].position -= gravity;
                 cubesTransform[i].position = cubePos;
             }
             
             /*Set the position of each vertex of the line based on the cube position.
              * Since this method only takes absolute World space positions, it has 
              * been subtracted by the current game object position.*/
             lRenderer.SetPosition(i, cubePos - goTransform.position);
         }
         
     }
 
 
     
     //Audio Play Buttons
     public void  GoVoiceClip01(){
         audio.PlayOneShot(VoiceClip01);
     }
 }
 


screen-shot-2015-02-26-at-122650-pm.png (186.6 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KnightRiderGuy · Feb 27, 2015 at 04:57 PM 0
Share

I would have thought there was a simple answer to this but so far no luck?!?

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

disable / enable mixer audio effect in C#? 1 Answer

does unity 5 pitch shifter audio effect change playback speed? 1 Answer

Audio Distortion effects? 0 Answers

multi Coloured Audio Waveform? 1 Answer

This script opens up an Audio Source but what would I need to do to get it to open up a Resonance Audio Source instead? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges