Unity类银河恶魔城学习记录1-12 PlayerComboAttack源代码 P39

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

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

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

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

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

    private int comboCounter;

    private float lastTimeAttacked;//距离上一次攻击的时间
    private float comboWindow = 2;//可以间隔的时间
    public PlayerPrimaryAttack(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
    }

    public override void Exit()
    {
        base.Exit();
        comboCounter++;
        lastTimeAttacked = Time.time;
    }

    public override void Update()
    {
        base.Update();
        if(triggerCalled)
        {
            stateMachine.ChangeState(player.idleState);
        }
    }
}
相关推荐
ABAP 成21 分钟前
.NET Framework 4.0可用EXCEL导入至DataTable
c#
DKPT24 分钟前
正则表达式
java·数据库·笔记·学习·正则表达式
chuxinweihui1 小时前
数据结构——二叉树,堆
c语言·开发语言·数据结构·学习·算法·链表
zhuyixiangyyds1 小时前
day36图像处理OpenCV
图像处理·笔记·学习
Mr__Miss1 小时前
JVM学习笔记
jvm·笔记·学习
周而复始 否极泰来1 小时前
深入浅出学会函数(上)
c语言·学习
ayas123191 小时前
数模学习:一,层次分析法
学习
yuhouxiyang1 小时前
学习海康VisionMaster之顶点检测
学习·计算机视觉
我的golang之路果然有问题2 小时前
给git配置SSH(github,gitee)
经验分享·笔记·git·学习·gitee·ssh·github
LVerrrr3 小时前
Missashe考研日记-day26
学习·考研