Unity类银河恶魔城学习记录1-14 AttackDirection源代码 P41

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考

此代码仅为较上一P有所改变的代码

【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili

PlayerPrimaryAttackState.cs
cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPrimaryAttackState : PlayerState
{
    //p38 2.从ground进入

    private int comboCounter;

    private float lastTimeAttacked;//距离上一次攻击的时间
    private float comboWindow = 2;//可以间隔的时间
    public PlayerPrimaryAttackState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        if(comboCounter >2||Time.time>comboWindow+lastTimeAttacked)//当计数器超过2和间隔时间大于window时,进入第一个攻击动作
        {
            comboCounter = 0;
        }
        Debug.Log(comboCounter);

        player.anim.SetInteger("ComboCounter", comboCounter);//设置animtor里的comboCounter

        #region 选择攻击方向
        float attackDir = player.facingDir;

        if(xInput != 0)
        {
            attackDir = xInput;
        }
        #endregion
                                                                   //使其能改变攻击方向
        player.SetVelocity(player.attackMovement[comboCounter].x * attackDir, player.attackMovement[comboCounter].y);//给角色初速度,让角色在攻击触发时移动一点

        stateTimer = .1f;
    }

    public override void Exit()
    {
        base.Exit();
        player.StartCoroutine("BusyFor", .15f);
        comboCounter++;
        lastTimeAttacked = Time.time;
    }

    public override void Update()
    {
        base.Update();
        if(stateTimer<0)
        {
            player.ZeroVelocity();
        }//1.修改移动时攻击时后可以移动的BUG
        //2.但给了点时间模拟惯性可以动一点
        if (triggerCalled)
        {
            stateMachine.ChangeState(player.idleState);
        }
    }
}
相关推荐
oier_Asad.Chen43 分钟前
【OI学习笔记】Floyed-Warshall算法解决传递闭包问题
c++·笔记·学习·算法·图论·最短路·传递闭包
鱼听禅1 小时前
C#学习笔记-添加编译参数到程序集自动更新程序编译时间
笔记·学习·c#
香菜TTT1 小时前
LangChain框架_学习笔记
笔记·学习·langchain
春水碧于天,画船听雨眠1 小时前
LangChain学习笔记(二)
笔记·学习·langchain
不正经学生1 小时前
C语言指针进阶:const 和野指针——给指针加锁,向野指针宣战
c语言·开发语言·c++·算法·c#
MartinYeung52 小时前
[论文学习]AdvWeb:针对VLM驱动的Web Agent的可控黑盒攻击
学习
colman wang2 小时前
vibe coding学习手册
学习
210Brian2 小时前
STM32学习笔记(四)OLED显示屏与Keil调试
笔记·stm32·学习
盖世汤猿2 小时前
AUTOSAR BSW 全栈开发学习计划(35岁危机)
学习
czhc11400756632 小时前
# ProcessJob 构造函数 — 语法与概念
c#