Log in or register to post comments

problem with sound during touch

February 19, 2012 - 11:44am #1

hi , i have a problem with my application . I have animation which is supposed to have walking steps sound during it`s movement .. but when i touch the phone the animation begin to move but the walking steps sound occurs after my finger left the screen ( after the animation stop walking , the sound begins )
i don`t know what is the problem with my script . here is mine

var stepsound: AudioClip;
var jump: AudioClip;
var start: AudioClip;
function Update () {

var fingerCount = 0;
for (var touch : Touch in Input.touches) {
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
fingerCount++;
}
if (fingerCount == 2){

animation.Play("walk");
transform.Translate(0,0,1);
audio.clip = stepsound;
audio.Play();

}

if (fingerCount == 1){
audio.clip = jump;
audio.Play();

animation.Play("jump");

}

if (Input.deviceOrientation == DeviceOrientation.FaceDown){
transform.localPosition=Vector3( 0 , 0 , 0 );
animation.Rewind("walk");
audio.clip = start;
audio.Play();

}
if (fingerCount == 0){
animation.Stop("walk");

}

}

Re: problem with sound during touch

February 19, 2012 - 4:17pm #2

hi,
i realy don't see where this is an qcar related question so you might be better of in unity answers or the unity forum/. this forum is dedicated to the qcar/vuforia sdk and unity plugin and half of the threads you start have nothing to do with that.
however having a quick look at your code the problem might be that if you call this in the update function you assign the clip again every frame and start it new. so the only time the clip can actually played completely is when you call audio.Play() for the last time (which is the frame before you lift your finger). my suggestion would be to try using "TouchPhase.Began" and "TouchPhase.Ended" to control the audio playback and see if this solves the problem. hope this helps.
best,
stefan

Log in or register to post comments