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);
        }
    }
}
相关推荐
星火开发设计4 分钟前
二叉树详解及C++实现
java·数据结构·c++·学习·二叉树·知识·期末考试
zxy284722530113 分钟前
利用C#对接BotSharp本地大模型AI Agent示例(2)
人工智能·c#·api·ai agent·botsharp
xiaoxiaoxiaolll14 分钟前
《Light: Science & Applications》超表面偏振态与偏振度完全独立控制新范式
学习
sww_102644 分钟前
JVM基础学习
jvm·学习·测试工具
工程师0071 小时前
C#中的CIL(公共中间语言)
开发语言·c#·中间语言cil
ysn111111 小时前
.NET性能测试工具BenchmarkDotNet
测试工具·c#
num_killer1 小时前
小白的Jenkins学习
运维·python·学习·jenkins
Every exam must be1 小时前
12.2 vue学习02
学习
sunfove1 小时前
照度 (E) 与亮度 (L) 的关系
学习
HL_风神2 小时前
设计原则之单一职责原则
c++·学习·设计模式·单一职责原则