Serge
Serge

Reputation: 2129

"Interruption" callback when another animation starts for the same object in DOTween

I have a method which is called on button tap which fades audio volume and mutes when completes:

MusicBox.musicAudioSource.DOFade(0.0f, 1.0f).OnComplete(() => { MusicBox.musicAudioSource.mute = true; });

If I tap on button quicker than 1 second than OnComplete() doesn't call. What callback I should use for those cases?

Upvotes: 0

Views: 449

Answers (1)

nalnpir
nalnpir

Reputation: 1197

Since DOFade does something with the object in a period of time, the problem is you are setting the variable to do something again before it finishes the first time, and thus its setting the time to 0 again ( I dont know how it works interally but i had a problem like this with an animation before ).

What you should be doing, is waiting for completion before activating the button again, something like disabling the button and then reenabling it should do the trick.

Upvotes: 1

Related Questions