ゲーム作って軌跡はまだ使ったことが無いんだけど、やっぱりあった方が派手になるのでちょっと練習してみた
基本、ParticleSystemですね。
攻撃アニメーションが終わったらtrailを止めないといけないので、アニメーションの終了判定が必要
animInfo = anim.GetCurrentAnimatorStateInfo(0); float animTimer = animInfo.normalizedTime%1.0f;
animInfo.normalizedTimeは、0~1までが返る(元のアニメーションが何秒であろうと正規化されて0~1が返る)
注意しないといけないのはループした場合は、0に戻らずに1から始まる。さらに次のループは2から始まる
よって1で割って余りを取得すれば、0~1で判定できる
GetCurrentAnimatorStateInfo(0)は毎回取得しないとダメらしい。
(normalizedTime%1)が前フレームより減ったらアニメが終了したので、パーティクルを止めて、ランダムに次のパーティクルを選ぶ
アニメーションはtestの値で切り替えてるので、アニメーションも切り替える
これで、次々に違うアニメを再生しながら、違うtrail演出を行う
Animator anim; AnimatorStateInfo animInfo; public int trailNo; public ParticleSystem[] pa; float preTime=0; void Start() { anim = GetComponent<Animator>(); trailNo = Random.Range(0, pa.Length); pa[trailNo].Play(); anim.SetInteger("test", Random.Range(0,3) ); } void Update() { animInfo = anim.GetCurrentAnimatorStateInfo(0); float animTimer = animInfo.normalizedTime%1.0f; //Debug.Log("time="+(animTimer) ); if (preTime > animTimer) { pa[trailNo].Stop(); trailNo = Random.Range(0, pa.Length); pa[trailNo].Play(); anim.SetInteger("test", Random.Range(0, 3)); } preTime = animTimer; }