视频教程: 如何使用触发器按边界检测节点
注意
每个视频都有英文,俄文和中文字幕。
警告
本教程使用SDK版本2.18创建。这些建议不适用于早期版本。
当任何节点(碰撞体或任何其他类型)进入内部或离开World Trigger时,WorldTrigger都会触发回调。
触发器可以通过其边界框检测任何类型的节点。
为了方便您使用,本视频中展示的组件代码如下:
DeleteObject.cs
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class DeleteObject : Component
{
WorldTrigger worldTrigger;
void enter_event_handler(Node target)
{
// Delete the object on entering the trigger
target.DeleteLater();
}
void Init()
{
// Cast Node to WorldTrigger
worldTrigger = node as WorldTrigger;
if(worldTrigger){
// Subscribe for Enter event to perform actions
// when a node enters the trigger
worldTrigger.EventEnter.Connect(enter_event_handler);
}
}
void Update()
{
// Render node's visualizer
node.RenderVisualizer();
}
}
Mover.cs
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class Mover : Component
{
void Init()
{
// write here code to be called on component initialization
}
void Update()
{
// move the node down
node.Translate(new vec3(0.0f, 0.0f, Game.IFps * -1.0f));
// render the bounding box
Visualizer.RenderBoundBox(node.BoundBox, mat4.IDENTITY, new vec4(1.0f, 0.0f, 0.0f, 1.0f));
}
}
要启用可视化工具,请在AppWorldLogic.cpp或任何合适的组件中的Init()方法中添加以下代码:
源代码 (C#)
// Enable Visualizer
Unigine.Console.Run("show_visualizer 1");
本页面上的信息适用于 UNIGINE 2.19.1 SDK.
最新更新:
2025-03-04
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)