概要
下記のスクリプトを使用することで、
このようなシンプルな待機アニメーションを実装できます
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; } }
参考ツイート
Simple idle animation:
— Sergey Veraksich (@iveseni) 2017年1月3日
- scale Y to 1.05 and Z to 0.95
- scale Y to 0.95 and Z to 1.05
- repeat#unitytips #gamedev #indiedev #madewithunity pic.twitter.com/cW4o3mENRT