Reputation:
I'm trying to get the mic to record when I press on a button (onClick
). The mic can capture and playback if I put the code into function Start()
. Could anyone tell me what I'm doing wrong to make this work with an onClick
button action?
#pragma strict
static var reco : AudioClip;
function onClick() {
var aud = GetComponent.<AudioSource>();
reco = Microphone.Start("Built-in Microphone", false, 2, 44100);
aud.clip = reco;
aud.Play()
}
Upvotes: 3
Views: 1054
Reputation: 7100
Your call to GetComponent is using some C#. Change that line to the following:
var aud = gameObject.GetComponent(AudioSource);
Upvotes: 1