There is a problem with my script...
It says in line 30 is a problem. Also when I try to add my script to an empty game object it says that the script does not exist.
using UnityEngine; using System.Collections;
public class AudioManager : MonoBehaviour {
 float masterVolumePercent = .2f;
 float sfxVolumePercent = 1;
 float musicVolumePercent = 1f;
 
 AudioSource[] musicSources;
 int activeMusicSourceIndex;
 
 public static AudioManager instance;
 
 Transform audioListener;
 Transform playerT;
 
 void Awake() {
     
     instance = this;
     
     musicSources = new AudioSource[2];
     for (int i = 0; i < 2; i++) {
         GameObject newMusicSource = new GameObject ("Music source " + (i + 1));
         musicSources[i] = newMusicSource.AddComponent<AudioSource> ();
         newMusicSource.transform.parent = transform;
     }
     
     audioListener = FindObjectOfType<AudioListener> ().transform;
     playerT = FindObjectOfType<Player> ().transform;
 }
 
 void Update() {
     if (playerT != null) {
         audioListener.position = playerT.position;
     }
 }
 
 public void PlayMusic(AudioClip clip, float fadeDuration = 1) {
     activeMusicSourceIndex = 1 - activeMusicSourceIndex;
     musicSources [activeMusicSourceIndex].clip = clip;
     musicSources [activeMusicSourceIndex].Play ();
     
     StartCoroutine(AnimateMusicCrossfade(fadeDuration));
 }
 
 public void PlaySound(AudioClip clip, Vector3 pos) {
     if (clip != null) {
         AudioSource.PlayClipAtPoint (clip, pos, sfxVolumePercent * masterVolumePercent);
     }
 }
 
 IEnumerator AnimateMusicCrossfade(float duration) {
     float percent = 0;
     
     while (percent < 1) {
         percent += Time.deltaTime * 1 / duration;
         musicSources [activeMusicSourceIndex].volume = Mathf.Lerp (0, musicVolumePercent * masterVolumePercent, percent);
         musicSources [1-activeMusicSourceIndex].volume = Mathf.Lerp (musicVolumePercent * masterVolumePercent, 0, percent);
         yield return null;
     }
 }
 
               }
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
How to stop a sound playing once another starts? (C#) 1 Answer
Enemy AI: Player attacke when in FOV 0 Answers
How do I make somthing happen when the Player reaches a certain x, y, z position? 0 Answers
load scene after video ended 2 Answers
Get player and enemy hit bars to respond to each others attack not their own 1 Answer