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

activate

简介

activate 是 Yuka.js 库的一种方法,用于激活(启用)实体或组件。当实体或组件已添加到引擎并准备好在场景中被使用时,应使用此方法。

语法

entity.activate();
component.activate();

参数

无。

返回值

无。

示例

以下示例演示了如何在实体和组件中使用 activate 方法。

import { Entity, Component } from 'yuka';

const entity = new Entity();
entity.activate(); // 激活实体

class MyComponent extends Component {
  constructor() {
    super();
    this.active = false;
  }

  activate() {
    this.active = true;
  }
}

const myComponent = new MyComponent();
myComponent.activate(); // 激活组件,将 active 属性设置为 true

注意事项

  • 如果在添加实体或组件之前尝试激活(调用 activate),则会引发错误。
  • 可以使用 deactivate 方法来停用实体或组件。