/// <summary> /// Called when an enemy should fire. If there are already MAX_ENEMY_MISSILES, then no firing will /// take place. Checks the ACTIVE CHILD count, since pooling is used to spawn/despawn (activeate/deactive) /// enemy missiles. /// </summary> /// <param name="enemy"></param> private bool enemyFireMissile(EnemyController enemy) { int activeCount = 0; bool fired = false; for (int cnt = 0; cnt < EnemyMissileContainer.childCount; cnt++) { if (EnemyMissileContainer.GetChild(cnt).gameObject.activeInHierarchy == true) { activeCount++; } } // Fire a missile from the invader if the maximum number of active missiles don't already exist. if (activeCount < GameGlobals.MAX_ENEMY_MISSILES) { GameObject missile = RFObjectPool.Spawn(EnemyMissilePrefab, Vector3.zero, Quaternion.identity); if (missile != null) { MissileController mc = missile.GetComponent <MissileController>(); mc.EnemyFired(enemy.gameObject); fired = true; } } return(fired); }
// Update is called once per frame void Update() { Vector3 pos = transform.position; pos.y += (yvel * Time.deltaTime); transform.position = pos; // Spawn a trace. Traces have a limited lifetime; they don't actully move--just shrink down and despawn // However, there can be quite a few on screen at once, so they are spawned/despawed with an object pool if (dropTime <= 0.0f) { GameObject trace = RFObjectPool.Spawn("MissileTrail", pos, Quaternion.identity); dropTime = TracerSpawnDelay; } dropTime -= Time.deltaTime; if (pos.y > GameGlobals.MISSILE_CONSTRAINT_Y || pos.y < -GameGlobals.MISSILE_CONSTRAINT_Y) { killMissile(); } }