Advertisement
EmperorDuck

Untitled

Jan 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Fire : MonoBehaviour {
  6.  
  7. public ParticleSystem shoot;
  8.  
  9. public bool isPlaying;
  10. public bool isReloading;
  11. public bool canShoot;
  12. public GameObject playerRotate;
  13. public float defaultSpriteAngle = 0;
  14.  
  15. private int ammo;
  16.  
  17. void Start()
  18. {
  19. shoot.Stop();
  20. isPlaying = false;
  21. isReloading = false;
  22. ammo = 3;
  23. canShoot = true;
  24. }
  25.  
  26. void Update()
  27. {
  28. if (canShoot == true)
  29. {
  30. if (Input.GetKey(KeyCode.Q))
  31. {
  32. if (ammo > 0)
  33. {
  34. shoot.Emit(5);
  35. StartCoroutine(Pause());
  36. isPlaying = true;
  37. canShoot = false;
  38. isReloading = false;
  39. ammo -= 1;
  40. Debug.Log("ammo = " + ammo);
  41. }
  42. }
  43.  
  44. if (ammo <= 0)
  45. {
  46. StartCoroutine(Reload());
  47. isReloading = true;
  48. isPlaying = false;
  49. canShoot = false;
  50. }
  51.  
  52. if (ammo > 3)
  53. {
  54. ammo = 3;
  55. }
  56.  
  57. }
  58. }
  59.  
  60. IEnumerator Pause()
  61. {
  62. yield return new WaitForSeconds(1);
  63. isPlaying = false;
  64. canShoot = true;
  65. }
  66.  
  67. IEnumerator Reload()
  68. {
  69. yield return new WaitForSeconds(3);
  70. ammo += 3;
  71. isPlaying = false;
  72. isReloading = false;
  73. canShoot = true;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement