/// <summary> /// Spawns projectile. /// </summary> public void ShootBullet() { timerShoot = maxTimerShoot; EnemyBulletController enemyBulletController = ((GameObject)Instantiate(bullet, transform.position + _dir * 0.2f, _bulletAngle)).GetComponent <EnemyBulletController> (); enemyBulletController.enemy = this; if (!firstBullet) { firstBullet = enemyBulletController; } else if (!lastBullet) { lastBullet = enemyBulletController; firstBullet.next = lastBullet; lastBullet.prev = firstBullet; } else { lastBullet.next = enemyBulletController; enemyBulletController.prev = lastBullet; lastBullet = enemyBulletController; } spriteAnimator.SetBool("Shoot", false); }
/// <summary> /// Removes all bullets from scene. /// </summary> public void RemoveAllBullets() { while (firstBullet) { lastBullet = firstBullet.next; Destroy(firstBullet.gameObject); firstBullet = lastBullet; } firstBullet = null; lastBullet = null; }
/// <summary> /// Removes bullet from scene. /// </summary> /// <param name="bullet">The bullet to remove.</param> public void RemoveBullet(EnemyBulletController bullet) { if (bullet.prev) { if (bullet.next) { bullet.prev.next = bullet.next; bullet.next.prev = bullet.prev; } else { bullet.prev.next = null; lastBullet = bullet.prev; if (firstBullet == lastBullet) { lastBullet = null; } } } else { if (bullet.next) { bullet.next.prev = null; firstBullet = bullet.next; if (firstBullet == lastBullet) { lastBullet = null; } } else { firstBullet = null; lastBullet = null; } } }