import { _decorator, Component, Node } from 'cc'; const { ccclass, property, executeInEditMode } = _decorator; @ccclass('WaitArea') @executeInEditMode export class WaitArea extends Component { @property(Node) waitNodes: Node = null!; // 实际存放杯子的节点 // 直接使用waitNodes的子节点管理 get cups() { return this.waitNodes.children; } start() { } update(deltaTime: number) { } // 从右向左排列 arrangeCups() { const startX = -40; const spacing = -150; this.cups.forEach((cup, index) => { cup.setPosition(startX + index * spacing, 0, 0); }); // console.log('WaitArea 杯子数量: ', this.cups.length); } addCup(cup: Node) { cup.setParent(this.waitNodes); this.arrangeCups(); } takeCup(): Node | null { if (this.cups.length === 0) return null; const cup = this.cups.pop()!; cup.removeFromParent(); this.arrangeCups(); return cup; } }