1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Unity3D] プレイヤーに攻撃アニメーションの実装

Posted at

プレイヤーに攻撃アニメーションをつける

1, 攻撃アニメーションをドラッグし、idleとwalkからmake transitionをつける。(idleには帰りのmake transitionをつける)
583D4E77-3273-4560-A846-540974191C69_4_5005_c.jpeg

2, ParametarsでTriggerでAttakを作成し、Conditionsに設定する。
各Transitionに設定する。(idleに帰るTransitionは設定なしでOK)
HasExitTimeのチェックを外し、Transitiopn Duratorは0にする。
3760A9E4-71C5-43B2-97F5-9E67EB866E50_4_5005_c.jpeg

138EC850-FA60-4C56-A537-1CF6D0050531_4_5005_c.jpeg

466D9E8D-C6A4-49A0-BD58-8D0EDB98A019_4_5005_c.jpeg

3, idleアニメーションを選択し、Transitionsの順番を変更する。
(idleから攻撃を優先する)
CF39EC2B-48B3-4832-929E-566A2FCA7F6F.jpeg
4, PlayerManagerに下記のスクリプトを書く
(Vを押すと攻撃アニメーションが発動する)

PlayerManager
//攻撃
        if (Input.GetKeyDown(KeyCode.V))
        {
            animator.SetTrigger("Attack");
        }

攻撃しながら移動できてしまうバグの修正

1, Attackを選択し、AddBehaviourからPlayerAttackBehaviourを作成する
805A949D-6ED7-4CF1-B1A7-65E7174F164D.jpeg

2, PlayerAttackBehaviourに下記のコードを記述する

PlayerAttackBehaviour
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerBrooklynBehaviour : StateMachineBehaviour
{
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.GetComponent<PlayerManager>().moveSpeed = 0;
    }

    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {

    }

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.GetComponent<PlayerManager>().moveSpeed = 3;
    }

    // OnStateMove is called right after Animator.OnAnimatorMove()
    //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //    // Implement code that processes and affects root motion
    //}

    // OnStateIK is called right after Animator.OnAnimatorIK()
    //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //    // Implement code that sets up animation IK (inverse kinematics)
    //}
}
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?