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 trial

Game Development How to Make a Video Game Game Audio Additional Audio Scripting

J R
J R
2,037 Points

I get the Bird Foot Steps sound but not the Player Movement Sounds.

Hi,

I can get the bird steps sound but not the player. I noticed when I hit play button and start playing, the "Random Sound Player (Script) component's checkbox doesn't get checked as the Bird's one does. Any ideas?

3 Answers

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi J R,

Could you please post your Random Sound Player script for me to have a look please?

J R
J R
2,037 Points
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 FixedUpdate () {
        //Increment a timer to count up to restarting
        soundTimer = soundTimer + Time.deltaTime;
        if (soundTimer >= soundTimerDelay) {

        // ... reset the timer ...
            soundTimer = 0f;

        //... choose a random sound...
            AudioClip randomSound = soundClips[Random.Range (0,soundClips.Count-1)];

        //... and play the sound.
            audioSource.PlayOneShot (randomSound);


        }

    }
}
John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi J R,

Have you correctly linked the RandomSoundPlayer script with the Player GameObject in the inspector?

There should be a Field in the Inspector for the Player GameObject called "Player Footsteps", does this field have the script "Player Footsteps (RandomSoundPlayer)" in it?

J R
J R
2,037 Points

Yes, I have a "Player Footsteps" field in the "Player" GameObject's inspector and this field is linked with the "Player FootSteps (RandomSoundlayer)". Still no sounds are coming when I play the game.

Seth Kroger
Seth Kroger
56,414 Points

What about the PlayerMovement.cs script? Can you post that to see if the sound script if being enabled and disabled right?

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

How strange, I didn't seem to see anything obviously wrong with your code.

Have you tried going back over the video and seeing if you went wrong somewhere or missed something?