Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

John Moron
1,658 PointsRandomSoundplayer wont load
I think my code looks correct is there something I'm doing wrong. My audio script won't load in unity, unity tells me to fix any errors but there aren't any.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RandomPlayerEdi : MonoBehaviour {
private AudioSource audioSource;
[SerializeField]
private List<AudioClip> soundClips = new List<AudioClip>();
[SerializeField]
private float soundTimerDelay = 3f;
private float soundTimer;
// Use this for initialization
void Start () {
audioSource = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update () {
// Increment a timer to count up to restarting.
soundTimer = soundTimer + Time.deltaTime;
// if time timer reaches the delay...
if (soundTimer >= soundTimerDelay) {
// ...reset the timer...
soundTimer = 0f;
//...choose a ramdom sound...
AudioClip randomSound = soundClips[Random.Range (0, soundClips.Count)];
//...and play the sound.
audioSource.PlayOneShot (randomSound);
}
}
}

Cameron Button
1,084 PointsI'm having this problem too, have you found a solution?

Jason Anders
Treehouse Moderator 145,692 PointsHey Cameron Button,
If you haven't had your issue resolved yet, please post your question in a separate thread. It's best to do this from the Video/challenge you first encounter the problem, by clicking the "Get Help" button and following the prompts. Make sure "include code" is checked.
This will ensure that the Community will be more able to assist you.

Cameron Button
1,084 PointsJason Anders thank you, but I figured it out. I even left an answer down below! :)
2 Answers

Cameron Button
1,084 PointsI think I have it figured out
The line....
"public class RandomPlayerEdi : MonoBehaviour"
should read...
"public class RandomSoundPlayer : MonoBehaviour"

John Moron
1,658 PointsOhh omg I would never have thought about that!

Cameron Button
1,084 PointsJohn Moron let me know if it works

John Moron
1,658 PointsIt worked! Thank you so much! For your help! Now I can finally finish!!

John Moron
1,658 PointsHello Pablo sorry I thought I had my question in my post. I updated it please help me fix this I really need to move on.
Pablo Rocha
10,142 PointsPablo Rocha
10,142 PointsUpdated your question for readability :)