Last active
June 5, 2017 14:28
-
-
Save muzudho/20b770968efb66315365a70db7542b41 to your computer and use it in GitHub Desktop.
Unityで2D格闘ゲームを作るときに欲しいと思われる、アニメのフレームと当たり判定の合わせ方 ref: http://qiita.com/muzudho1/items/b89a2ac150c39b6b3f60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ヒットボックスのスプライト | |
void Update() | |
{ | |
// ~略~ | |
hitboxTransform.Translate( | |
offsetX - hitboxTransform.position.x, | |
offsetY - hitboxTransform.position.y, | |
hitboxTransform.position.z | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// キャラクターのスプライト | |
using UnityEngine; | |
// 中略 | |
void Update() | |
{ | |
// 中略 | |
// animator は GetComponent<Animator>(); で取得しておく | |
AnimationClip clip = animator.GetCurrentAnimatorClipInfo(0)[0].clip; | |
AnimatorStateInfo animeStateInfo = animator.GetCurrentAnimatorStateInfo(0); | |
float normalizedTime = animeStateInfo.normalizedTime; | |
// これが、今表示されているフレームの計算式 | |
int currentFrame = Mathf.FloorToInt((normalizedTime % 1.0f) * clip.frameRate); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AnimatorStateInfo animeStateInfo = animator.GetCurrentAnimatorStateInfo(0); | |
// これがハッシュ | |
int hash = animeStateInfo.fullPathHash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
// ~中略 | |
Dictionary<int, string> hashToName = new Dictionary<int, string>(); | |
// 自分でハッシュを作る方法 | |
int hash = Animator.StringToHash( "Base Layer.SAtkHK"); | |
hashToName.Add( hash, "Base Layer.SAtkHK"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment