ECS Framework API / tryGetComponent
Function: tryGetComponent()
tryGetComponent<
T>(entity,componentType):undefined|ComponentInstance<T>
Defined in: packages/core/src/ECS/TypedEntity.ts:54
尝试获取组件
Type Parameters
T
T extends ComponentConstructor
Parameters
entity
实体实例
componentType
T
组件类型构造函数
Returns
undefined | ComponentInstance<T>
组件实例或undefined
Example
typescript
const health = tryGetComponent(entity, Health);
if (health) {
health.value -= 10;
}