title: Change width parameter of Trail Renderer with audio spectrum C# Script in Unity
body: <p>I am trying to find a way to dynamically change the width parameter of a trail renderer with the audio spectrum from an audio file. I have successfully been able change the scale of the game object, but not the actual width parameter of the trail renderer itself. Here is the code that works to dynamically change the scale of using the audio spectrum. Any help or suggestions would be much appreciated! Thanks</p>
  
  <p>Code to change scale using audio spectrum:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class trailTest : MonoBehaviour {
  public float width = 5.0f;
  public bool useCurve = true;
  private TrailRenderer tr;
  public int numberOfObjects = 1;
  
  
  void Start ()
  {
      tr = GetComponent&lt;TrailRenderer&gt; ();
      tr.material = new Material (Shader.Find ("Sprites/Default"));
  }
  
  void Update ()
  {
      AnimationCurve curve = new AnimationCurve ();
      if (useCurve) {
          curve.AddKey (0.0f, 0.0f);
          curve.AddKey (1.0f, 1.0f);
      } else {
          curve.AddKey (0.0f, 1.0f);
          curve.AddKey (1.0f, 1.0f);
      }
  
      float [] spectrum = AudioListener.GetSpectrumData (1024, 0, FFTWindow.Hamming);
      for (int i = 0; i &lt; numberOfObjects; i++) {
          Vector3 previousScale = tr.transform.localScale;
          previousScale.y = Mathf.Lerp (previousScale.y, spectrum [i] * 80, Time.deltaTime * 30);
          tr.transform.localScale = previousScale;
  
        }
     }
   }
  </code></pre>