Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public enum BulletType
  6. {
  7. UpDown,
  8. OnlyLeft,
  9. Cross,
  10. OnlyRight,
  11.  
  12. //OnlyUp,
  13. //OnlyDown,
  14. //OnlyUpperLeft,
  15. //OnlyUpperRight,
  16. //OnlyBottomRight,
  17. //OnlyBottomLeft,
  18. }
  19.  
  20. public enum BulletModifier
  21. {
  22. Laser,
  23. Plasma,
  24. Poison,
  25. Bursting,
  26. None,
  27. }
  28.  
  29. public class Shooting_Old : MonoBehaviour
  30. {
  31. public Transform[] firePoint;
  32.  
  33. public GameObject[] bulletPrefabs;
  34. public GameObject currentBulletPrefab;
  35.  
  36. private BulletType bulletType = BulletType.OnlyRight;
  37. private BulletModifier bulletModifier = BulletModifier.None;
  38.  
  39. int bulletTypeCount = 1;
  40. int bulletModCount = 1;
  41.  
  42. [Range(0.1f, 0.5f)]
  43. public float shootingDelay;
  44.  
  45. bool canShootAfterDelay = true;
  46.  
  47. bool shoot = false;
  48.  
  49. public float bulletForce = 20f;
  50.  
  51. protected void Update()
  52. {
  53. if (Input.GetButton("Shoot") && canShootAfterDelay)
  54. {
  55. shoot = true;
  56. }
  57.  
  58. if (Input.GetButtonDown("SwitchBulletType"))
  59. {
  60. SwitchBulletType_2();
  61. }
  62.  
  63. if (Input.GetButtonDown("SwitchBulletModifier"))
  64. {
  65. SwitchBulletModifier(5);
  66. }
  67. }
  68.  
  69. protected void FixedUpdate()
  70. {
  71. Shoot();
  72. }
  73.  
  74. void Shoot()
  75. {
  76. if (shoot)
  77. {
  78. ApplyShootingForce();
  79. StartCoroutine(ShootingDelay(shootingDelay));
  80. shoot = false;
  81. }
  82. }
  83.  
  84. void ApplyShootingForce()
  85. {
  86. switch (bulletModifier)
  87. {
  88. case BulletModifier.None:
  89. currentBulletPrefab = bulletPrefabs[0];
  90. if (bulletType == BulletType.Cross)
  91. {
  92. shootingDelay = 0.2f;
  93. }
  94. else
  95. {
  96. shootingDelay = 0.15f;
  97. }
  98. break;
  99.  
  100. case BulletModifier.Laser:
  101. currentBulletPrefab = bulletPrefabs[1];
  102. shootingDelay = 0.15f;
  103. break;
  104.  
  105. case BulletModifier.Plasma:
  106. currentBulletPrefab = bulletPrefabs[2];
  107. shootingDelay = 0.1f;
  108. break;
  109.  
  110. case BulletModifier.Poison:
  111. currentBulletPrefab = bulletPrefabs[3];
  112. shootingDelay = 0.15f;
  113. break;
  114.  
  115. case BulletModifier.Bursting:
  116. currentBulletPrefab = bulletPrefabs[4];
  117. shootingDelay = 0.4f;
  118. break;
  119. }
  120.  
  121.  
  122. switch (bulletType)
  123. {
  124. case BulletType.OnlyRight:
  125. RightShoot(firePoint[0]);
  126. break;
  127.  
  128. case BulletType.UpDown:
  129. UpDown(firePoint[3], firePoint[2]);
  130. break;
  131.  
  132. case BulletType.OnlyLeft:
  133. LeftShoot(firePoint[1]);
  134. break;
  135.  
  136. case BulletType.Cross:
  137. UpDown(firePoint[4], firePoint[5], firePoint[6], firePoint[7]);
  138. break;
  139. }
  140. }
  141.  
  142. void RightShoot(Transform firePoint)
  143. {
  144. GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation);
  145. Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
  146. rb2d.AddForce(firePoint.right * bulletForce, ForceMode2D.Impulse);
  147. }
  148.  
  149. void UpDown(Transform firePoint, Transform firePoint_2)
  150. {
  151. GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation * Quaternion.Euler(0, 0, 90));
  152. Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
  153. rb2d.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
  154.  
  155. GameObject bullet_2 = Instantiate(currentBulletPrefab, firePoint_2.position, firePoint_2.rotation * Quaternion.Euler(0, 0, -90));
  156. Rigidbody2D rb2d_2 = bullet_2.GetComponent<Rigidbody2D>();
  157. rb2d_2.AddForce(firePoint_2.up * -1 * bulletForce, ForceMode2D.Impulse);
  158. }
  159.  
  160. void LeftShoot(Transform firePoint)
  161. {
  162. GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation * Quaternion.Euler(0, 0, 180));
  163. Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
  164. rb2d.AddForce(firePoint.right * -1 * bulletForce, ForceMode2D.Impulse);
  165. }
  166.  
  167. void UpDown(Transform firePoint, Transform firePoint_2, Transform firePoint_3, Transform firePoint_4)
  168. {
  169. GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation * Quaternion.Euler(0, 0, 45));
  170. Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
  171. rb2d.AddForce(new Vector2(1, 1) * bulletForce, ForceMode2D.Impulse);
  172.  
  173. GameObject bullet_2 = Instantiate(currentBulletPrefab, firePoint_2.position, firePoint_2.rotation * Quaternion.Euler(0, 0, 135));
  174. Rigidbody2D rb2d_2 = bullet_2.GetComponent<Rigidbody2D>();
  175. rb2d_2.AddForce(new Vector2(-1, 1) * bulletForce, ForceMode2D.Impulse);
  176.  
  177. GameObject bullet_3 = Instantiate(currentBulletPrefab, firePoint_3.position, firePoint_3.rotation * Quaternion.Euler(0, 0, -135));
  178. Rigidbody2D rb2d_3 = bullet_3.GetComponent<Rigidbody2D>();
  179. rb2d_3.AddForce(new Vector2(-1, -1) * bulletForce, ForceMode2D.Impulse);
  180.  
  181. GameObject bullet_4 = Instantiate(currentBulletPrefab, firePoint_4.position, firePoint_4.rotation * Quaternion.Euler(0, 0, -45));
  182. Rigidbody2D rb2d_4 = bullet_4.GetComponent<Rigidbody2D>();
  183. rb2d_4.AddForce(new Vector2(1, -1) * bulletForce, ForceMode2D.Impulse);
  184. }
  185.  
  186. void SwitchBulletType_2()
  187. {
  188. if(bulletType == BulletType.OnlyRight)
  189. {
  190. bulletType = BulletType.UpDown;
  191. }
  192. else if(bulletType == BulletType.Cross)
  193. {
  194.  
  195. }
  196. }
  197.  
  198. void SwitchBulletModifier(int numbers)
  199. {
  200. if (bulletModCount <= numbers)
  201. {
  202. bulletModifier = (BulletModifier)bulletModCount;
  203. bulletModCount++;
  204. }
  205. else
  206. {
  207. bulletModCount = 1;
  208. bulletModifier = (BulletModifier)bulletModCount;
  209. bulletModCount++;
  210. }
  211. }
  212.  
  213. IEnumerator ShootingDelay(float delay)
  214. {
  215. canShootAfterDelay = false;
  216. yield return new WaitForSeconds(delay);
  217. canShootAfterDelay = true;
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement