Skip to content

Instantly share code, notes, and snippets.

@muzudho
Last active June 5, 2017 14:28
Show Gist options
  • Save muzudho/20b770968efb66315365a70db7542b41 to your computer and use it in GitHub Desktop.
Save muzudho/20b770968efb66315365a70db7542b41 to your computer and use it in GitHub Desktop.
Unityで2D格闘ゲームを作るときに欲しいと思われる、アニメのフレームと当たり判定の合わせ方 ref: http://qiita.com/muzudho1/items/b89a2ac150c39b6b3f60
// ヒットボックスのスプライト
void Update()
{
// ~略~
hitboxTransform.Translate(
offsetX - hitboxTransform.position.x,
offsetY - hitboxTransform.position.y,
hitboxTransform.position.z
);
}
// キャラクターのスプライト
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);
}
AnimatorStateInfo animeStateInfo = animator.GetCurrentAnimatorStateInfo(0);
// これがハッシュ
int hash = animeStateInfo.fullPathHash;
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