日志2025.2.8

news/2025/2/9 8:10:01 标签: unity, 算法, 游戏程序

日志2025.2.8

1.增加了近战敌人攻击类型
public struct AttackData
{
    public string attackName;
    public float attackRange;
    public float attackIndex;
    public float animationSpeed;
    public float moveDistance;
    public AttackType_Melee attackType;
}

public enum AttackType_Melee
{
    Close, Charge
}


public class AttackState_Melee : EnemyState
{
    private Enemy_Melee enemy;
    private Vector3 moveDestination;
    private float lastTime;

    public AttackState_Melee(Enemy enemyBase, EnemyStateMachine stateMachine, string animBoolName) : base(enemyBase, stateMachine, animBoolName)
    {
        enemy = (Enemy_Melee)enemyBase;
    }

    public override void Enter()
    {
        enemy.animator.SetFloat("AttackAnimationSpeed", enemy.attackData.animationSpeed);
        enemy.animator.SetFloat("AttackIndex", enemy.attackData.attackIndex); SetDestination();

        base.Enter();

        SetDestination();
        lastTime = Time.time;

        enemy.agent.isStopped = true;
        
    }

    public override void Exit()
    {
        base.Exit();

        SetUpNextAttack();
    }

    public override void Update()
    {
        base.Update();

        if (triggerCalled)
        {
            stateMachine.ChangeState(enemy.recoveryState);
            return;
        }

        if(Time.time - lastTime > 0.5f)
        {
            AttackMove();
        }

    }

    private void SetUpNextAttack()
    {
        int recoveryIndex = enemy.PlayerClose() ? 1 : 0;
        enemy.animator.SetFloat("RecoveryIndex", recoveryIndex);

        enemy.attackData = GetAttackData();
        Debug.Log(enemy.attackData.attackName);
    }

    //随机获取攻击方式
    private AttackData GetAttackData()
    {
        List<AttackData> validAttackList = new List<AttackData>(enemy.attackList);

        //如果玩家足够近,则删去冲锋攻击
        if (enemy.PlayerClose())
        {
            validAttackList.RemoveAll(parameter => parameter.attackType == AttackType_Melee.Charge);
        }

        int random = Random.Range(0, validAttackList.Count);
        return validAttackList[random];
    }

    private void SetDestination()
    {
        Vector3 dir = enemy.playerTransform.position - enemy.transform.position;
        dir.y = 0;
        dir.Normalize();
        moveDestination = enemy.transform.position + dir * enemy.attackData.moveDistance;
    }

    private void AttackMove()
    {
        enemy.transform.position = Vector3.Lerp(enemy.transform.position, moveDestination, Time.deltaTime * 2);
    }


}


http://www.niftyadmin.cn/n/5845808.html

相关文章

已经安装了Visual C++ 2015-2022 Redistributable,但运行程序时,提示找不到VCRUNIME140_1D.dll

VCRUNTIME140_1.dll 功能&#xff1a;这是 Visual C 2015 及更高版本运行时库的更新版本&#xff0c;提供了与 VCRUNTIME140.dll 类似的功能&#xff0c;但可能包含一些改进和新特性。 用途&#xff1a;用于支持使用 Visual C 2015 及更高版本编译的应用程序。 VCRUNTIME140…

Unity项目接入xLua的一种流程

1. 导入xlua 首先导入xlua&#xff0c;这个不用多说 2. 编写C#和Lua交互脚本 基础版本&#xff0c;即xlua自带的版本 using System.Collections; using System.Collections.Generic; using UnityEngine; using XLua; using System; using System.IO;[Serializable] public…

MariaDB *MaxScale*实现mysql8读写分离

1.MaxScale 是干什么的&#xff1f; MaxScale是maridb开发的一个mysql数据中间件&#xff0c;其配置简单&#xff0c;能够实现读写分离&#xff0c;并且可以根据主从状态实现写库的自动切换&#xff0c;对多个从服务器能实现负载均衡。 2.MaxScale 实验环境 中间件192.168.12…

使用opencv解析视频,通过图片比对,筛选出每一帧视频的变化

记录瞬间 最近碰到一个问题&#xff0c;在客户端上操作时&#xff0c;存在背景判断的情况&#xff0c;对自动化实现此操作增加难度。 所以考虑到实际的使用&#xff0c;将一些计算机视觉技术加入到实际的使用中&#xff0c;来解决此问题。 import os import cv2 import numpy#…

车机音频参数下发流程

比如以audioControlWrapper.setParametersToAmp(keyPairValues); 下发banlance为例&#xff0c;链路如下 hal层 1. AudioControl.cpp hardware\interfaces\automotive\audiocontrol\aidl\default\AudioControl.cpp ndk::ScopedAStatus AudioControl::setParametersToAmp(co…

算法与数据结构(字符串相乘)

题目 思路 这道题我们可以使用竖式乘法&#xff0c;从右往左遍历每个乘数&#xff0c;将其相乘&#xff0c;并且把乘完的数记录在nums数组中&#xff0c;然后再进行进位运算&#xff0c;将同一列的数进行相加&#xff0c;进位。 解题过程 首先求出两个数组的长度&#xff0c;…

【读书笔记·VLSI电路设计方法解密】问题46:什么是bug覆盖率

在IC设计项目的验证过程中&#xff0c;功能测试&#xff08;通过使用测试平台&#xff09;有助于定位设计错误或漏洞。这个验证过程有三个阶段&#xff1a;构建和启动测试平台、验证基本测试用例以及验证边界情况。 在前两个阶段&#xff0c;漏洞很容易被检测到&#xff0c;因…

Python实现GO鹅优化算法优化支持向量机SVM回归模型项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后关注获取。 1.项目背景 在当今数据驱动的世界中&#xff0c;机器学习技术被广泛应用于各种领域&#xff0c;如金融、医疗、…