AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

sendMessage

功能介绍

EntityManager 类中 sendMessage 方法用于向指定实体发送消息。

语法

entityManager.sendMessage(entityName, message)

参数

  • entityName:必填,要发送消息的实体名称。
  • message:必填,要发送的消息。

返回值

该方法没有返回值。

使用示例

// 获取 Yuka 库的 EntityManager 类
const EntityManager = Yuka.EntityManager;

// 创建一个实体管理器
const entityManager = new EntityManager();

// 添加两个实体到管理器
const entity1 = new MyEntity();
const entity2 = new MyEntity();
entityManager.add(entity1);
entityManager.add(entity2);

// 向实体2发送消息
entityManager.sendMessage(entity2.name, 'Hey, how are you?');

在上面的示例中,我们首先创建了一个实体管理器,并添加了两个实体 entity1entity2。然后我们调用了 sendMessage 方法,向实体2发送了一条消息。