LoginSignup
0
1

More than 5 years have passed since last update.

コンボ攻撃

Last updated at Posted at 2017-11-27

以下の作業はこの記事のことを一通りやってからやって下さい♪
設定のやり方が分からないっていう人もそちらに書いてあるので参考にして下さい♪
※Animatorのattack1→Exitの矢印はコンボ攻撃をやるなら削除して下さい。

アニメーションの読み込み、アニメーションの名前の変更、アニメーションの遷移の設定
combo1.png

アニメーションの遷移の条件の設定
combo2.png

Combo.cs
using UnityEngine;
using System.Collections;

public class AttackTest : StateMachineBehaviour
{


    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.SetBool("Attack", false);
    }
       override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (Input.GetKeyDown(KeyCode.Z))


        {
            animator.SetBool("Attack", true);
        }
    }

    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.SetBool("Attack", false);
    }

}

Comboスクリプトの貼り付け
combo3.png

攻撃中のみ判定を表示するスクリプトの作成
この記事で作成した剣の当たり判定に貼り付けます。
既に貼り付けている場合は追記部分を追記して下さい

GetAnimationInfo.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetAnimationInfo : MonoBehaviour
{

    public GameObject obj;
    private AnimatorStateInfo stateInfo;
    private Animator anim;

    // Use this for initialization
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {

        stateInfo = anim.GetCurrentAnimatorStateInfo(0);
        if (stateInfo.IsName("Base Layer.attack1") || stateInfo.IsName("Base Layer.attack2") || stateInfo.IsName("Base Layer.attack3"))//追記部分
        {
            obj.SetActive(true);
        }
        else
        {
            obj.SetActive(false);
        }}}

攻撃ボタンを押した回数によって攻撃が変わります
combo攻撃.gif

目次に戻る

0
1
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
0
1