- Home /
Question by
KhaosLimit · May 21, 2015 at 09:16 AM ·
javascripterrorsoundplay
'Play' is not a member of 'Object'
I'm trying to play a sound when a sphere touchs the ground and I got this script:
#pragma strict
@RequireComponent(AudioSource)
public var collide;
var audios;
function Start() {
audios = GetComponent.<AudioSource>();
}
function OnCollisionEnter() {
audios.Play(collide, 0.7F);
}
But when I try to run it, the compiler gives me this error:
Assets/Collide Sound.js(10,16): BCE0019: 'Play' is not a member of 'Object'.
What should I do to fix it OR if I'm doing it wrong, how can I make the ball have a "bounce sound"?
Comment
Best Answer
Answer by tanoshimi · May 21, 2015 at 07:26 PM
What is audios
? You haven't declared its type, so Unity can only assume it's a generic object. And generic objects don't have Play () methods, as the error states. If you want it to be an AudioSource, declare it as such - change line 4:
var audios : AudioSource;
Your answer
Follow this Question
Related Questions
Implicit Downcast warning. 1 Answer
Play Animation on trigger enter 1 Answer
Sound system not working correctly 0 Answers
Animation Crossfade won't play but Animation Play does 1 Answer
Make footstep script 2 Answers