对象池补充
先说下上一篇对象池的一个问题。用脚本,在一个SpawnPool,添加多个prefab,
运行游戏时,只有第一个prefab预加载了规定个数,当用到其他prefab时,
其他prefab才出现在pool中,而且数量会无限增加! 但是第一个prefab却不会,
还是会限制在 limitAmount规定的个数。如果将一个对象对应一个SpawnPool,运行时正常!
这个问题很是诡异,目前还没有找到原因。
using UnityEngine;
using System.Collections;
using PathologicalGames;
public class SpawnTest : MonoBehaviour {
public GameObject prefab, prefab1;
//对象池
SpawnPool spawnPool;
// Use this for initialization
void Start () {
spawnPool = PoolManager.Pools["Spawn"];
//每隔0.5秒,调用一次CreatPerfab方法
InvokeRepeating("CreatPerfab", 1f, 0.2f);
}
// Update is called once per frame
void Update () {
}
void CreatPerfab() {
//从对象池中取出物体,并且设置它的位置
spawnPool.Spawn(prefab.transform, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
spawnPool.Spawn(prefab1.transform, new Vector3(transform.