Glad you have found something that works for you Damien.
Note, if your code is all in the one class, you can improve it a little by not duplicating the GetComponent<AudioSource>
calls you have, for example;
using UnityEngine;
public class Hacker : MonoBehaviour
{
private AudioSource audioSource; // member variable to hold reference to AudioSource component
private void Start()
{
audioSource = GetComponent<AudioSource>(); // get reference to AudioSource component (once)
}
// ...
}
In your existing methods, where you then declare a new variable to store the reference to the audio source, you can simply remove those lines, as you’ll already have a member variable, with a reference to the AudioSource component you can use;
void ShowWinScreen(string input)
{
currentScreen = Screen.Win;
ShowLevelRewards();
if (input == "menu")
{
audioSource.Stop(); // use existing member variable
ShowMainMenu("Hello " + yourName);
}
}
void ShowLevelRewards()
{
switch (level)
{
case 1:
audioSource.PlayOneShot(mario); // use existing member variable
Debug.Log(mario);
Terminal.WriteLine(@"
// ...
}