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 trialSasha Greene
439 PointsCan not access the class RandomSoundPlayer
So everything was going really well until the part in the video where we use the class RandomSoundPlayer as a type in both the bird and player movement scripts. Inside of the RandomSoundPlayer I can access the class, but in the PlayerMovement and BirdMovement Script Files whenever I type RandomSoundPlayer it is underlined in red. I'm using visual studio if that helps. Here is my RandomSoundPlayer Code:
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class RandomSoundPlayer : 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 timer to count up to restart
soundTimer = soundTimer + Time.deltaTime;
//if timer reaches delay
if (soundTimer >= soundTimerDelay)
{
//Reset the timer
soundTimer = 0f;
//Choose a random sound
AudioClip randomSound = soundClips[Random.Range(0,soundClips.Count)];
//And play sound
audioSource.PlayOneShot(randomSound);
}
}
}
Sasha Greene
439 PointsI've just come back to this now because it was frustrating me last night, I believe it was just a bug in visual studio. as soon as i loaded everything back up it worked just fine. Sorry for taking up your time but i do appreciate the response!
Henrique Vignon
Courses Plus Student 6,415 PointsHenrique Vignon
Courses Plus Student 6,415 PointsThe RandomSoundPlayer script seems fine, could post either your BirdMovement or PlayerMovement scripts where you're having problems?