Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. public void ShootLasers()
  2. {
  3. if(isTripleFireActive == true)
  4. {
  5. TripleFiring();
  6. }
  7. else if (isTripleFireActive == false)
  8. {
  9. SingleFire();
  10. }
  11.  
  12. }
  13.  
  14.  
  15. public void TripleFiring()
  16. {
  17. if (Input.GetMouseButtonDown(0))
  18. {
  19. continueTripleFire = StartCoroutine(TripleNonStopFiring());
  20. }
  21. if (Input.GetMouseButtonUp(0))
  22. {
  23. StopCoroutine(continueTripleFire);
  24. }
  25.  
  26. }
  27.  
  28. public void SingleFire()
  29. {
  30. if (Input.GetMouseButtonDown(0))
  31. {
  32. continueFiring = StartCoroutine(FireNonStop());
  33. }
  34. if (Input.GetMouseButtonUp(0))
  35. {
  36. StopCoroutine(continueFiring);
  37. }
  38. }
  39.  
  40.  
  41. public void TripleFiringIsActive()
  42. {
  43. StartCoroutine(TripleFireState());
  44. }
  45.  
  46.  
  47. IEnumerator FireNonStop()
  48. {
  49. while (true)
  50. {
  51. GameObject laserBullet = Instantiate(playerLaser, transform.position + new Vector3(0, .5f, 0), transform.rotation) as GameObject;
  52. laserBullet.GetComponent<Rigidbody2D>().velocity = new Vector2(0, laserSpeed);
  53. yield return new WaitForSeconds(laserFiringTime);
  54. }
  55. }
  56.  
  57. IEnumerator TripleNonStopFiring()
  58. {
  59. while(isTripleFireActive == true)
  60. {
  61. GameObject laserBulletMiddle = Instantiate(playerLaser, transform.position + new Vector3(0, .5f, 0), transform.rotation) as GameObject;
  62. GameObject laserBulletRight = Instantiate(playerLaser, transform.position + new Vector3(.18f, 0, 0), transform.rotation) as GameObject;
  63. GameObject laserBulletLeft = Instantiate(playerLaser, transform.position + new Vector3(-.2f, 0, 0), transform.rotation) as GameObject;
  64.  
  65. laserBulletMiddle.GetComponent<Rigidbody2D>().velocity = new Vector2(0, laserSpeed);
  66. laserBulletRight.GetComponent<Rigidbody2D>().velocity = new Vector2(0, laserSpeed);
  67. laserBulletLeft.GetComponent<Rigidbody2D>().velocity = new Vector2(0, laserSpeed);
  68. yield return new WaitForSeconds(triplelaserFiringTime);
  69. }
  70. }
  71.  
  72. IEnumerator TripleFireState()
  73. {
  74. isTripleFireActive = true;
  75. yield return new WaitForSeconds(5f);
  76. isTripleFireActive = false;
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement