import { _decorator, Component, Node, Vec3, v3, randomRangeInt } from 'cc'; import { Res } from '../../core/res/res'; import { ResCache } from '../../core/res/res-cache'; import { Msg } from '../../core/msg/msg'; const { ccclass, property } = _decorator; @ccclass('DropItem') export class DropItem extends Component { itemName: string = ''; groupIndex = 0; public init (name: string, effectIndex: number, _groupIndex: number) { this.itemName = name; this.node.name = name; this.groupIndex = _groupIndex; // Load Item. var prefab = ResCache.Instance.getPrefab(name + '_pickup'); const dropNode = Res.inst(prefab, this.node.children[4], v3(0, 0, 0)); this.node.on('picked', this.picked, this); // random drop effect. const index = effectIndex; this.node.children[index].active = true; } onDestroy () { this.node.off('picked', this.picked, this); } public picked () { Msg.emit('msg_remove_item', this.groupIndex); // Remove object. this.node.destroy(); } }