BlasterWeapon.cs 836 B

12345678910111213141516171819202122232425262728293031323334
  1. using UnityEngine;
  2. namespace Assets.Scripts.BlasterWeapon
  3. {
  4. internal sealed class BlasterWeapon : MonoBehaviour
  5. {
  6. public float BulletSpeed = 1;
  7. public GameObject BulletPrefab;
  8. public bool Enabled;
  9. public float LifeTime = 2f;
  10. private void Start()
  11. {
  12. InvokeRepeating("Fire", 1f, 0.5f);
  13. }
  14. private void Update()
  15. {
  16. }
  17. private void Fire()
  18. {
  19. if (!Enabled)
  20. return;
  21. var bulletClone = Instantiate(BulletPrefab, transform.position, transform.rotation);
  22. var blasterBullet = bulletClone.GetComponent<BlasterBullet>();
  23. blasterBullet.Speed = BulletSpeed;
  24. blasterBullet.LifeTime = LifeTime;
  25. Destroy(bulletClone, LifeTime);
  26. }
  27. }
  28. }