Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum BulletType
- {
- UpDown,
- OnlyLeft,
- Cross,
- OnlyRight,
- //OnlyUp,
- //OnlyDown,
- //OnlyUpperLeft,
- //OnlyUpperRight,
- //OnlyBottomRight,
- //OnlyBottomLeft,
- }
- public enum BulletModifier
- {
- Laser,
- Plasma,
- Poison,
- Bursting,
- None,
- }
- public class Shooting_Old : MonoBehaviour
- {
- public Transform[] firePoint;
- public GameObject[] bulletPrefabs;
- public GameObject currentBulletPrefab;
- private BulletType bulletType = BulletType.OnlyRight;
- private BulletModifier bulletModifier = BulletModifier.None;
- int bulletTypeCount = 1;
- int bulletModCount = 1;
- [Range(0.1f, 0.5f)]
- public float shootingDelay;
- bool canShootAfterDelay = true;
- bool shoot = false;
- public float bulletForce = 20f;
- protected void Update()
- {
- if (Input.GetButton("Shoot") && canShootAfterDelay)
- {
- shoot = true;
- }
- if (Input.GetButtonDown("SwitchBulletType"))
- {
- SwitchBulletType_2();
- }
- if (Input.GetButtonDown("SwitchBulletModifier"))
- {
- SwitchBulletModifier(5);
- }
- }
- protected void FixedUpdate()
- {
- Shoot();
- }
- void Shoot()
- {
- if (shoot)
- {
- ApplyShootingForce();
- StartCoroutine(ShootingDelay(shootingDelay));
- shoot = false;
- }
- }
- void ApplyShootingForce()
- {
- switch (bulletModifier)
- {
- case BulletModifier.None:
- currentBulletPrefab = bulletPrefabs[0];
- if (bulletType == BulletType.Cross)
- {
- shootingDelay = 0.2f;
- }
- else
- {
- shootingDelay = 0.15f;
- }
- break;
- case BulletModifier.Laser:
- currentBulletPrefab = bulletPrefabs[1];
- shootingDelay = 0.15f;
- break;
- case BulletModifier.Plasma:
- currentBulletPrefab = bulletPrefabs[2];
- shootingDelay = 0.1f;
- break;
- case BulletModifier.Poison:
- currentBulletPrefab = bulletPrefabs[3];
- shootingDelay = 0.15f;
- break;
- case BulletModifier.Bursting:
- currentBulletPrefab = bulletPrefabs[4];
- shootingDelay = 0.4f;
- break;
- }
- switch (bulletType)
- {
- case BulletType.OnlyRight:
- RightShoot(firePoint[0]);
- break;
- case BulletType.UpDown:
- UpDown(firePoint[3], firePoint[2]);
- break;
- case BulletType.OnlyLeft:
- LeftShoot(firePoint[1]);
- break;
- case BulletType.Cross:
- UpDown(firePoint[4], firePoint[5], firePoint[6], firePoint[7]);
- break;
- }
- }
- void RightShoot(Transform firePoint)
- {
- GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation);
- Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
- rb2d.AddForce(firePoint.right * bulletForce, ForceMode2D.Impulse);
- }
- void UpDown(Transform firePoint, Transform firePoint_2)
- {
- GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation * Quaternion.Euler(0, 0, 90));
- Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
- rb2d.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
- GameObject bullet_2 = Instantiate(currentBulletPrefab, firePoint_2.position, firePoint_2.rotation * Quaternion.Euler(0, 0, -90));
- Rigidbody2D rb2d_2 = bullet_2.GetComponent<Rigidbody2D>();
- rb2d_2.AddForce(firePoint_2.up * -1 * bulletForce, ForceMode2D.Impulse);
- }
- void LeftShoot(Transform firePoint)
- {
- GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation * Quaternion.Euler(0, 0, 180));
- Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
- rb2d.AddForce(firePoint.right * -1 * bulletForce, ForceMode2D.Impulse);
- }
- void UpDown(Transform firePoint, Transform firePoint_2, Transform firePoint_3, Transform firePoint_4)
- {
- GameObject bullet = Instantiate(currentBulletPrefab, firePoint.position, firePoint.rotation * Quaternion.Euler(0, 0, 45));
- Rigidbody2D rb2d = bullet.GetComponent<Rigidbody2D>();
- rb2d.AddForce(new Vector2(1, 1) * bulletForce, ForceMode2D.Impulse);
- GameObject bullet_2 = Instantiate(currentBulletPrefab, firePoint_2.position, firePoint_2.rotation * Quaternion.Euler(0, 0, 135));
- Rigidbody2D rb2d_2 = bullet_2.GetComponent<Rigidbody2D>();
- rb2d_2.AddForce(new Vector2(-1, 1) * bulletForce, ForceMode2D.Impulse);
- GameObject bullet_3 = Instantiate(currentBulletPrefab, firePoint_3.position, firePoint_3.rotation * Quaternion.Euler(0, 0, -135));
- Rigidbody2D rb2d_3 = bullet_3.GetComponent<Rigidbody2D>();
- rb2d_3.AddForce(new Vector2(-1, -1) * bulletForce, ForceMode2D.Impulse);
- GameObject bullet_4 = Instantiate(currentBulletPrefab, firePoint_4.position, firePoint_4.rotation * Quaternion.Euler(0, 0, -45));
- Rigidbody2D rb2d_4 = bullet_4.GetComponent<Rigidbody2D>();
- rb2d_4.AddForce(new Vector2(1, -1) * bulletForce, ForceMode2D.Impulse);
- }
- void SwitchBulletType_2()
- {
- if(bulletType == BulletType.OnlyRight)
- {
- bulletType = BulletType.UpDown;
- }
- else if(bulletType == BulletType.Cross)
- {
- }
- }
- void SwitchBulletModifier(int numbers)
- {
- if (bulletModCount <= numbers)
- {
- bulletModifier = (BulletModifier)bulletModCount;
- bulletModCount++;
- }
- else
- {
- bulletModCount = 1;
- bulletModifier = (BulletModifier)bulletModCount;
- bulletModCount++;
- }
- }
- IEnumerator ShootingDelay(float delay)
- {
- canShootAfterDelay = false;
- yield return new WaitForSeconds(delay);
- canShootAfterDelay = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement