Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Created January 15, 2020 22:49
Show Gist options
  • Save nkjzm/b0a4f56d9787b1f6abe1102f496b9348 to your computer and use it in GitHub Desktop.
Save nkjzm/b0a4f56d9787b1f6abe1102f496b9348 to your computer and use it in GitHub Desktop.
DOTweenでポップにアニメーションするボタン
using UnityEngine.UI;
using DG.Tweening;
using UnityEngine;
namespace nkjzm
{
/// <summary>
/// ポップに押されるボタン
/// </summary>
public class PopButton : Button
{
Tweener tweener = null;
new void Start()
{
base.Start();
// ボタンアニメーション
onClick.AddListener(() =>
{
// 再生中のアニメーションを停止/初期化
if (tweener != null)
{
tweener.Kill();
tweener = null;
transform.localScale = Vector3.one;
}
tweener = transform.DOPunchScale(
punch: Vector3.one * 0.1f,
duration: 0.2f,
vibrato: 1
).SetEase(Ease.OutExpo);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment