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 trialRasmus Hall
1,260 Pointsplaying Audio
here's my code:
GameObject talkObject = GameObject.Find("Talking Sound"); AudioSource talk = talkObject.GetComponent<AudioSource>(); audio.Play(talk);
1 Answer
George Popovich
15,055 PointsHey!
audio.Play(talk) doesn't do anything because "audio" doesn't exist. Instead, you should call the ".Play()" method on the "talk" audio source. Also, ".Play()" only takes a float argument, which will determine the delay after which the sound will be played. It does not accept an audio source as an argument.
So the code should look like this:
GameObject talkObject = GameObject.Find("Talking Sound");
AudioSource talk = talkObject.GetComponent<AudioSource>();
talk.Play();
Hope this helps!