public void Shoot() { if (myBase.zeroEnergy) { isShooting = false; return; } if (TypeTir % 3 == 1 && lastShoot > rateTir1) { Bullet myBullet = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet.GetComponent <Bullet>().Angle(0); myBase.currentEnergy -= energyTir1; lastShoot = 0; } else if (TypeTir % 3 == 2 && lastShoot > rateTir2) { Bullet myBullet = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet.GetComponent <Bullet>().Angle(0.5f); Bullet myBullet2 = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet2.GetComponent <Bullet>().Angle(-0.5f); lastShoot = 0; myBase.currentEnergy -= energyTir2; } else if (TypeTir % 3 == 0 && lastShoot > rateTir3) { Bullet myBullet = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet.GetComponent <Bullet>().Angle(1); Bullet myBullet2 = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet2.GetComponent <Bullet>().Angle(-1); Bullet myBullet3 = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet3.GetComponent <Bullet>().Angle(0.2f); Bullet myBullet4 = BulletFactory.Instance.GetBullet(BulletType.BONE, myStart.transform.position); myBullet4.GetComponent <Bullet>().Angle(-0.2f); lastShoot = 0; myBase.currentEnergy -= energyTir3; } if (myBase.currentEnergy <= 0) { myBase.zeroEnergy = true; } myBase.Energy(isShooting); }
// Update is called once per frame void Update() { speed = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); myEngine.move(speed, -1); if (Input.GetKey(KeyCode.Space)) { isShooting = true; myShoot.Shoot(); } else { isShooting = false; } if (Input.GetKeyDown(KeyCode.Tab)) { myShoot.UpdateTir(); } myShoot.lastShoot++; myBase.Energy(isShooting); }