mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-01-14 23:11:24 +00:00
28 lines
941 B
TypeScript
28 lines
941 B
TypeScript
import { Component, Prefab, Vec3, _decorator } from "cc";
|
|
import { ObjectPool } from "../../../Services/ObjectPool";
|
|
import { HealthPotion } from "./HealthPotion";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("HealthPotionSpawner")
|
|
export class HealthPotionSpawner extends Component {
|
|
@property(Prefab) public healthPotionPrefab: Prefab;
|
|
|
|
private healthPotionPool: ObjectPool<HealthPotion>;
|
|
|
|
public init(): void {
|
|
this.healthPotionPool = new ObjectPool<HealthPotion>(this.healthPotionPrefab, this.node, 5, "HealthPotion");
|
|
}
|
|
|
|
public spawn(position: Vec3): void {
|
|
const healthPotion: HealthPotion = this.healthPotionPool.borrow();
|
|
healthPotion.setup(position);
|
|
healthPotion.PickupEvent.on(this.return, this);
|
|
}
|
|
|
|
private return(healthPotion: HealthPotion): void {
|
|
healthPotion.PickupEvent.off(this.return);
|
|
this.healthPotionPool.return(healthPotion);
|
|
}
|
|
}
|