Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private bool powerUp = false;
- void Update()
- {
- Fire();
- }
- private void Fire()
- {
- if(powerUp == false)
- {
- if (Input.GetButtonDown("Fire1"))
- {
- firingCoroutine = StartCoroutine(FireContiuously());
- }
- if (Input.GetButtonUp("Fire1"))
- {
- StopCoroutine(firingCoroutine);
- }
- }
- else
- {
- if (Input.GetButtonDown("Fire1"))
- {
- firingCoroutine1 = StartCoroutine(FireContiuouslyGun1(10f));
- firingCoroutine2 = StartCoroutine(FireContiuouslyGun2(10f));
- }
- //I don't think this is needed!?
- if (Input.GetButtonUp("Fire1"))
- {
- StopCoroutine(firingCoroutine1);
- StopCoroutine(firingCoroutine2);
- //Unless you set the powerUp to false, because you might get infinite powerup, if my logic is correct, which probably isn't.
- //powerUp = false;
- }
- }
- //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- //If you want to combine the normal firing with the powerup, use this one
- //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- // if (Input.GetButtonDown("Fire1"))
- // {
- // firingCoroutine = StartCoroutine(FireContiuously());
- // }
- // if (Input.GetButtonUp("Fire1"))
- // {
- // StopCoroutine(firingCoroutine);
- // }
- // if(powerUp == true)
- // {
- // if (Input.GetButtonDown("Fire1"))
- // {
- // firingCoroutine1 = StartCoroutine(FireContiuouslyGun1(10f));
- // firingCoroutine2 = StartCoroutine(FireContiuouslyGun2(10f));
- // }
- // if (Input.GetButtonUp("Fire1"))
- // {
- // StopCoroutine(firingCoroutine1);
- // StopCoroutine(firingCoroutine2);
- //
- // powerUp = false;
- // }
- // }
- }
- IEnumerator FireContiuously()
- {
- while (true)
- {
- GameObject bullet = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
- bullet.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
- sfx.GetShootSFX();
- yield return new WaitForSeconds(firingPeriod);
- }
- }
- public void OnTriggerEnter2D(Collider2D doubleBullets)
- {
- if(doubleBullets.gameObject.CompareTag("Double Bullets"))
- {
- Destroy(doubleBullets.gameObject);
- StopCoroutine(FireContiuously() /* <- Isn't this suppose to be firingCoroutine? */ );
- powerUp = true;
- }
- }
- IEnumerator FireContiuouslyGun1(float timeLimit)
- {
- while (timeLimit > 0f)
- {
- timeLimit -= firingPeriod;
- GameObject bullet = Instantiate(projectile, gun1.transform.position, Quaternion.identity) as GameObject;
- bullet.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
- sfx.GetShootSFX();
- yield return new WaitForSeconds(firingPeriod); //Changed to firingPeriod
- }
- powerUp = false;
- }
- IEnumerator FireContiuouslyGun2(float timeLimit)
- {
- while (timeLimit > 0f)
- {
- timeLimit -= firingPeriod;
- GameObject bullet = Instantiate(projectile, gun2.transform.position, Quaternion.identity) as GameObject;
- bullet.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
- sfx.GetShootSFX();
- yield return new WaitForSeconds(firingPeriod); //Changed to firingPeriod
- }
- powerUp = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement