LoginSignup
1
2

More than 3 years have passed since last update.

AnimationEventレシピ ~アニメーションで当たり判定を切り替える~

Last updated at Posted at 2020-12-09

まずは@sanpeitaさんの記事を見てね
https://qiita.com/sanpeita/items/a11348e47f256b8d1cf3

問題点

剣プログラムに当たり判定を追加しただけだとどんな時でも剣が敵に当たるとダメージが発生してしまう

 /// 剣プログラム
 private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            Debug.Log("<size=30>当たった!!!</size>");
        }
    }

この記事でできること 剣を振り下ろしたときに敵を倒すようにする

MixamoからダウンロードしたアニメーションはAnimationEventを追加できない(ReadOnly)です。Ctrl+D/command+DでMixamoのモデルに入っているAnimationClipを複製。するとAnimationEventを追加できる(編集可能)になる。
スクリーンショット (262).png

    /// <summary>
    /// プレイヤープログラム
    /// </summary>

   [SerializeField,Header("剣の当たり判定")] BoxCollider SwordCol;

    void Start()
    {
        SwordCol.enabled = false;
    }

    /// <summary>
    /// 剣の当たり判定をON
    /// </summary>
    void AttackStart()
    {
        Debug.Log("AttackStart呼ばれた");
        SwordCol.enabled = true;
    }

    /// <summary>
    /// 剣の当たり判定をOFF
    /// </summary>
    void AttackEnd()
    {
        Debug.Log("AttackEnd呼ばれた");
        SwordCol.enabled = false;
    }

剣を振り下ろしている時のみ当たり判定がでるようになった
qitta.gif

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2