1

What we want to do

In the click event

  • The first time, the value will be sent without a wait time.
  • For the second action, the value is passed on one second after the event has settled down.

Problems

I was thinking that the following code could be used to achieve this if the Throttle process could be skipped only at the beginning.

GameObject button;
bool first = true;

button.onClick
      .AsObservable()
      .Throttle(TimeSpan.FromMillseconds(1000))
      .Subscribe(() => {// action});
}
Dai
  • 141,631
  • 28
  • 261
  • 374
harutaka
  • 61
  • 3
  • I'd advise against using _fancy tech_ such as _Reactive Extensions (Rx) and/or clones_ in a _**game**_ due to 1) noisy object generation 2) as with delegates risk of memory leaks if you don't unsubscribe (can be fatal if this traverses a new game level) 3) simpler alternatives available when making games. Basically if you are using delegates you are at risk. https://www.amazon.com/Engine-Architecture-Third-Jason-Gregory/dp/1138035459 –  Sep 08 '22 at 08:33

0 Answers0