Unity UIアニメーションを使いまわしたい
今回はUnityでUI演出を作成するときに、よく使う演出(テキストの点滅とか)を使いまわす方法です。
①それぞれのAnimationを設定する
ColorパラメータはRGBAをそれぞれ選択、Deleteで削除することができます。
こうすることで色の違うUIのAlpha値のみアニメーションさせたりできます。
②実験用にAnimationを再生するスクリプトを書く
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CallAnimation : MonoBehaviour { private void Start() { //赤色を点滅させる transform.Find("ImageRed").GetComponent<Animator>().Play("ColorAnim"); //青色を回転させる transform.Find("ImageBlue").GetComponent<Animator>().Play("RotationAnim"); //緑色を拡大、縮小させる transform.Find("ImageGreen").GetComponent<Animator>().Play("ScaleAnim"); //黄色を中央で上下させる transform.Find("ImageYellow").GetComponent<Animator>().Play("PositionAnim"); } }
このコードをCanvasにアタッチすると動くようになります。
こんな感じ↓
【わかゲームスタジオ】Unity UIAnimationSample
クリックで切り替わるようにしてみると、
【わかゲームスタジオ】Unity UIAnimationSampleChange