1
0

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でGetInstanceIDを使うと便利だったケース: 簡易UIアニメーション振動メソッドの実装

Posted at

前提

  • Dotweenが導入済みであること

これは何

  • GetInstanceIDがDotweenと相性がいいという気づきの紹介
  • 下の例でいうと対象のRectTransformを指定して振動開始・任意のタイミングで停止というメソッド
VibrateRect.cs
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

    public static void VibrateRect(bool isActive, RectTransform rect) {
        var id = rect.GetInstanceID();
        if (isActive) {
            if (DOTween.IsTweening(id)) {
                return;
            }
            var sq = DOTween.Sequence().SetId(id);
            sq.AppendInterval(2f);
            sq.Append(
                rect.DOPunchScale(
                    new Vector3(0.2f, 0.2f, 0.2f),
                    0.2f,
                    1,
                    1
                ).SetEase(Ease.OutExpo).SetLoops(4)
            );
            sq.SetLoops(100);
        } else {
            if (DOTween.IsTweening(id)) {
                DOTween.Complete(id);
            }
        }
    }
  • アニメーション時間の引数増やすのも賢い気がする
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?