protected void OnDisable() { if (doneSpawning) { rigidbody.velocity = Vector3.zero; if (catParticlePool == null) { catParticlePool = TapGOPoolSingleton <CatParticle> .PoolInstance(); } TapGameObject particle = catParticlePool.GetObject(); if (particle) { particle.gameObject.SetActive(true); particle.GetComponent <CatParticle>().PlayAtLocation(transform.position); } else { Debug.LogError("Could not play particle system"); } gameManager.IncScore(1); popSound.Play(); } doneSpawning = false; base.OnDisable(); }
public static TapGOPool CreatePool(GameObject templatePrefab, int amount) { if (amount <= 0) { Debug.LogError("Cannot create an empty pool!"); return(null); } if (templatePrefab.GetComponent <Template>() == null) { Debug.LogError("Object prefab not of template type!"); return(null); } if (poolInstance != null) { Debug.LogError("GameObjectPool already created!"); return(null); } lock (_createlock) { if (poolInstance == null && activePoolInstance == null) { // create a new instance of TapGOPool for our singleton GameObject newinstance = new GameObject("TapGOPool"); newinstance.AddComponent <TapGOPool>(); poolInstance = newinstance.GetComponent <TapGOPool>(); // create a new instance of ActiveTapGOPool GameObject newactiveinstance = new GameObject("activePool"); newactiveinstance.AddComponent <ActiveTapGOPool>(); activePoolInstance = newactiveinstance.GetComponent <ActiveTapGOPool>(); if (poolInstance == null || activePoolInstance == null) { Debug.LogError("Could not create poolInstance!"); } } else { return(poolInstance); } } // add our objects to the pool for (int i = 0; i < amount; i++) { TapGameObject prefab = (Instantiate(templatePrefab) as GameObject).GetComponent <TapGameObject>(); if (!prefab) { Debug.LogError("Not a TapGameObject!"); } prefab.gameObject.SetActive(false); // initially set object to be inactive prefab.transform.SetParent(poolInstance.transform); // set the created prefab to be a child of the pool object for cleanliness // initialize the activepool for the object // (we do this after setting it to active to make sure we don't call the OneEnable and OnDisable functions) prefab.activeTapGOPool = activePoolInstance; poolInstance.objectList.Add(prefab); } return(poolInstance); }
// Use this for initialization void Awake() { tapAreaSound = AudioManager.Instance().GetAudioSource("TapAreaSound"); activeTapAreaPool = TapGOPoolSingleton <TapArea> .ActivePoolInstance(); tapAreaPool = TapGOPoolSingleton <TapArea> .PoolInstance(); if (!activeTapAreaPool || !tapAreaPool) { Debug.LogError("Cannot find activeTapAreaPool!"); } }
void Start() { enemyPool = TapGOPoolSingleton <Enemy> .CreatePool(enemyPrefab, enemyPoolAmount); tapAreaPool = TapGOPoolSingleton <TapArea> .CreatePool(tapAreaPrefab, tapAreaPoolAmount); catParticlePool = TapGOPoolSingleton <CatParticle> .CreatePool(catParticlePrefab, catParticlePoolAmount); if (enemyPool == null || tapAreaPool == null || !playerBase || !catParticlePool) { Debug.LogError("GameObjectPool creation failed!"); } }
// Use this for initialization void Awake() { target = GameManager.Instance().playerBase.transform; spawnPoints = new List <Transform>(); activeEnemyPool = TapGOPoolSingleton <Enemy> .ActivePoolInstance(); enemyPool = TapGOPoolSingleton <Enemy> .PoolInstance(); if (!activeEnemyPool || !enemyPool || !target) { Debug.LogError("Cannot find activeEnemyPool!"); } // Build the spawner list from child objects with the "spawner" tag foreach (Transform t in transform.GetComponentsInChildren <Transform>()) { if (t.tag == "Spawner") { spawnPoints.Add(t); } } currtime = 0f; nexttime = timeBetweenSpawns; }