27
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityのButton連打を防ぎたい

Last updated at Posted at 2016-08-02

ボタンを連打させる挙動を防ぐコードのメモ

UniRxのThrottle

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UniRx;
using UniRx.Triggers;
using System;

public class ButtonSample : MonoBehaviour
{
    public Button Button;

    void Start()
    {
        this.Button
            .OnClickAsObservable()
            .TakeUntilDestroy(this)
            .ThrottleFirst(TimeSpan.FromMilliseconds(1000))
            .Subscribe(_ => { OnClick(); });
    }

    private void OnClick()
    {
    }
}

こんな感じでThrottleを使うと簡単にいける。

27
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?