I am getting this error but I have audio attached to it. I have deleted the component and even rebooted. Weird issue.
So here is the error:
MissingComponentException: There is no ‘AudioSource’ attached to the “Input-Escape-MainMenu” game object, but a script is trying to access it.
You probably need to add a AudioSource to the game object “Input-Escape-MainMenu”. Or your script needs to check if the component is attached before using it.
InputEscape+c__Iterator6.MoveNext () (at Assets/Extras Created/InputEscape.cs:47)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
InputEscape:Update() (at Assets/Extras Created/InputEscape.cs:40)
here is the code. It only gives the error after pressing the spacebar
using UnityEngine;
using System.Collections;
///////////////////////////////////////////////////////////////
public class InputEscape : MonoBehaviour
{
///////////////////////////////////////////////////////////////
public GameObject mainMenuBtn; // quit button
public GameObject nextBtn; // next button
public GameObject overHeadBtn; // overhead button
public GameObject effectNewBestScore;
new AudioSource audio;
public AudioClip menuSound51;
///////////////////////////////////////////////////////////////
void Awake()
{
audio = GetComponent<AudioSource>();
mainMenuBtn = GameObject.FindWithTag("MainMenuButton");
overHeadBtn = GameObject.FindWithTag("OverHeadButton");
effectNewBestScore = GameObject.FindWithTag("BestScore");
nextBtn = GameObject.FindWithTag("NextHoleButton");
}
///////////////////////////////////////////////////////////////
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
CanvasButtonsOnOff.fire1ButtonPressed = true;
mainMenuBtn.SetActive(false);
nextBtn.SetActive(false);
overHeadBtn.SetActive(false);
//destroy settings-1, settings-2.....courses
Destroy(GameObject.FindWithTag("settings-all"));
StartCoroutine(WaitForMainMenu2());
}
}
////////////////////////////////////////////
IEnumerator WaitForMainMenu2()
{
audio.PlayOneShot(menuSound51, 1f);
while (audio.isPlaying == true)
{
yield return null;
}
effectNewBestScore.SetActive(false);
Application.LoadLevel("MainMenu");
}
////////////////////////////////////////////
}
Now look at the pictures: