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);
        }
    }
}
相关推荐
曹牧1 小时前
C#:Obsolete
开发语言·c#
我是苏苏1 小时前
Web开发:使用C#的System.Drawing.Common将png图片转化为icon图片
开发语言·c#
阿蒙Amon1 小时前
C#每日面试题-is和as的区别
java·开发语言·c#
阿蒙Amon1 小时前
C#每日面试题-简述泛型约束
java·开发语言·c#
佳哥的技术分享2 小时前
Function<T, R> 中 apply,compose, andThen 方法总结
java·学习·r语言
阳明Coding2 小时前
golang从入门到通天—数据库操作(gorm框架使用)(最简单最详细的golang学习笔记)
笔记·学习·golang
AI视觉网奇2 小时前
ue5 开发 web socket server 实战2026
c++·学习·ue5
嗯嗯=2 小时前
STM32单片机学习篇6
stm32·单片机·学习
2301_797312262 小时前
学习Java42天
java·开发语言·学习
找了一圈尾巴2 小时前
智能体自演进框架-ACE(论文学习)
学习·提示词