[Unity][FlowCanvas][NodeCanvas] ForEach 不适合连接 Wait,FSM 的 SubFlowScript 接受不到事件

在Unity使用NodeCanvas的FlowCanvas进行游戏逻辑开发时,遇到一个foreach循环与Wait结合的问题,导致循环内Wait后只使用了最后一个index的参数。同时,尝试使用事件进行状态管理,但SubFlowScript无法接收到事件。尝试了thiscomponent和全局事件无果,最后通过调整流程实现功能,但对此现象感到困惑。

一开始我写的是对一个 id 列表的循环,用于生成敌人,每一次循环中都会 wait 一下作为生成敌人的间隔,循环的 index 对应敌人的不同生成参数
在测试中发现,敌人的生成设置只会使用 index = list.length-1 对应的生成参数
经过 debug 可以发现,foreach 的 index 仍然是正常传出来的,但是 wait 之后获取到的 index 全是 list.length-1
如图下所示,输出为:
0
1
111111
111111

在这里插入图片描述

后来我就想用事件做一个循环,每一次生成事件开始时都检查一遍生成记录是否大于等于规定生成数量,不是则进入生成流程,完成流程吼生成记录自增
但是测试之后发现这个脚本收不到事件
这个脚本是 LevelMgr 的 SFM 的 SubFlowScript,所以我在 LevelMgr 的 FlowScriptController 所引用的 FlowScript 里面接受我命名的生成事件,确实是接收到了
为了想办法让 SubFlowScript 接收到事件,我尝试了使用 thiscomponent 和 global event,都不行
最后只能使用首尾相连的笨方法了
唉,我不理解

在这里插入图片描述
在这里插入图片描述

The complete Visual Behaviour Authoring framework for Unity, empowering you to create advanced AI Behaviours and Logic, including three separate, fully featured, yet seamlessly interchangeable modules for you to choose and easily add in your game: • Behaviour Trees • Hierarchical State Machines • Dialogue Trees NodeCanvas is a production ready framework used by many awesome games including Kim, Pamela, Hurtworld, Shroud of the Avatar, Kingdom and Ghost of a Tale. [Games Showcase] Feature Highlights ------------------------------------- • Choose the right tool for the task at hand. • Design reactive Behaviour Trees and Hierarchical State Machines within an intuitive, designer friendly visual node editor: (Full Undo/Redo, Zoom In/Out, Multi-selection, Duplication, Copy/Pasting, JSON Import/Export, Groups, Comments and more) • Use local & global variables of any type, visually or in code, for creating reusable and actor-oriented, parametric behaviours, optionally saving and loading those variables between gaming sessions. • Data Bind variables with any component property of any type directly. • Sync variables automatically over the network using UNET, for creating multiplayer games. • Visually Debug behaviours with realtime, colorful and informative runtime debugging. • Live Edit everything while in play mode to perfectly understand your design goals and how to achieve them. • Utilize any existing code directly with advanced and extremely fast Reflection Tasks, automatically integrating Unity's and 3rd Party asset APIs. • Work with Lists/Arrays, Enums, Interfaces and pretty much ANY Variable Type you need out-of-the-box. • React to world changes and transfer data using the built-in Event System. • Reuse and Bind made behaviours among any number of different agents. • Organize your designs using Behaviour Sub-Trees and Sub-State Machines. • Extend NodeCanvas Framework to create your own Actions, Conditions, Nodes or even completely new modules with the e
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值