weight
是 Yuka js 库中的一个 Behavior。该 Behavior 用于处理实体的重量信息。
value
:重量的初始值,默认为 1。weight
实例。import { weight } from 'yuka';
const entityWeight = new weight(5);
设置实体的重量。
value
:重量的新值。entityWeight.setValue(8);
获取实体的当前重量。
const currentWeight = entityWeight.getValue();
增加实体的重量。
value
:要添加的重量值。entityWeight.add(3);
减少实体的重量。
value
:要减少的重量值。entityWeight.subtract(2);
import { weight } from 'yuka';
const entityWeight = new weight(5);
console.log(entityWeight.getValue()); // 输出:5
entityWeight.add(3);
console.log(entityWeight.getValue()); // 输出:8
entityWeight.subtract(2);
console.log(entityWeight.getValue()); // 输出:6