const { regClass, property } = Laya

@regClass()
export class AutoDestroy extends Laya.Script {
  declare owner: Laya.Box

  @property(Number)
  public lifeTime: number = 1

  // 组件被激活后执行，此时所有节点和组件均已创建完毕，此方法只执行一次
  onStart(): void {
    if (this.lifeTime < 1) {
      this.lifeTime = 1
    }
    Laya.timer.once(this.lifeTime * 1000, this, () => {
      this.owner.destroy()
    })
  }
}
