How can I make my script play on it's own without using an input button?

Hi all! I am doing a sound design degree, and to get extra marks in this particular module I need to do some coding.

So basically my code is all setup (watching youtube video’s as I am a complete beginner) so that when you press the space bar a random sound will play.

However I don’t want to have to press the space bar to activate, instead I would like for the sound to play at random times, but without playing more then one audio at a time. I have searched for hours and I can’t seem to find anything.

Any help on the matter would be greatly appreciated!

here is the current snippet of code, however if you require the whole thing in order to solve this let me know:

	void Update ()
	{
		if (Input.GetKeyDown ("space")) 
		{
			PlaySound ();
		}
	}

Thanks in advance!

You can either run a Coroutine, but I doubt you know what that is, or track the time passed. Save the current Time and set another variable to the time you want to wait until the next sound should play. In Update instead of waiting for your button, you wait for the ever increasing current time to be greater then the saved time plus your waittime. If that’s true, save Time again, set a new waittime and play the sound.