コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】シンプルな待機アニメーションを実装する

概要

f:id:baba_s:20171229105721g:plain

下記のスクリプトを使用することで、
このようなシンプルな待機アニメーションを実装できます

using UnityEngine;

public class IdleAnim : MonoBehaviour
{
    public float min = 0.95f;
    public float max = 1.05f;
    public float speed = 2;

    private float time;

    private void Update()
    {
        time += Time.deltaTime;
        var t = time * speed;
        var amount = Mathf.PingPong( t, 1 );
        var x = OutQuad( amount, 1, max, min );
        var y = OutQuad( 1 - amount, 1, max, min );
        var scale = transform.localScale;
        scale.x = x;
        scale.y = y;
        transform.localScale = scale;
    }

    private float OutQuad( float t, float total, float max, float min )
    {
        max -= min;
        t /= total;
        return -max * t * ( t - 2 ) + min;
    }
}

参考ツイート

参考サイト様

https://qiita.com/hart_edsf/items/962ac03281b871dcc0df