HomingCondomWeapon.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class HomingCondomWeapon : Weapon
  5. {
  6. public PoolObject homingCondomPrefab;
  7. public int homingAmmo;
  8. private int _homingAmmoLeft;
  9. private Pool _homingCondomPool;
  10. public override void Arm()
  11. {
  12. base.Arm();
  13. _homingCondomPool = Pool.Get(homingCondomPrefab);
  14. _homingAmmoLeft = homingAmmo;
  15. NotificationCenter.Post(NotificationType.UpdateWeaponUpgradeAmmoLeft, _homingAmmoLeft);
  16. NotificationCenter.AddListener(OnVirusSpawned, NotificationType.VirusSpawned);
  17. }
  18. public override void Disarm()
  19. {
  20. base.Disarm();
  21. NotificationCenter.RemoveListener(OnVirusSpawned, NotificationType.VirusSpawned);
  22. }
  23. void OnVirusSpawned(Notification note)
  24. {
  25. Virus virus = (Virus)note.data;
  26. PoolObject homingCondom = _homingCondomPool.Spawn();
  27. homingCondom.GetComponent<HomingCondom>().target = virus.transform;
  28. NotificationCenter.Post(NotificationType.FireIndependently, homingCondom);
  29. --_homingAmmoLeft;
  30. NotificationCenter.Post(NotificationType.UpdateWeaponUpgradeAmmoLeft, _homingAmmoLeft);
  31. }
  32. public override bool IsEmpty
  33. {
  34. get
  35. {
  36. return _homingAmmoLeft <= 0;
  37. }
  38. }
  39. }