Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn 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,860 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 :)