LoginSignup
1
1

More than 3 years have passed since last update.

【Unity】DoTweenを使ってUIを上下ループさせて目立たせる

Last updated at Posted at 2020-01-01

コード

UIPointer.cs
using UnityEngine;
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;

public class UIPointer : MonoBehaviour
{
    [SerializeField] private float _durationSeconds = 0.2f;

    private float _initY = 0;
    private float _endY = 0;
    [SerializeField] private float _moveY = 3f;

    private TweenerCore<Vector3, Vector3, VectorOptions> _tweener;

    public void InitDisplay(Vector3 position)
    {
        // 指定した位置に移動する
        transform.position = position;

        // 初期化
        _initY = transform.position.y;
        _endY = _initY - _moveY;

        // 表示する
        gameObject.SetActive(true);

        _tweener = transform
            .DOMoveY(_endY, duration: _durationSeconds)
            .SetEase(Ease.InCubic)
            .SetLoops(-1, LoopType.Yoyo)
            .Play();
    }

    private void OnDisable()
    {
        _tweener.Kill();
    }

    [ContextMenu("TestDisplay")]
    void TestDisplay()
    {
        InitDisplay(Vector3.zero);
    }
}

エディタ

image.png

デモ

参考

[Unity] DOTweenを使ってUI要素を点滅させる

余談

地味にコピペですぐ使えるコードが見つからなかったので記事にしました。

1
1
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
1