// Update is called once per frame void Update() { if (!player_Mover.isDead()) { timeSinceLastShoot += Time.deltaTime; if (energy < 100 && timeSinceLastShoot > delayShoot) { if (canFire) { increaseEnergy(Time.deltaTime * energyPerSecond); } else { increaseEnergy(Time.deltaTime * energyPerSecond * 0.75f); } } if (fire) { if (timeSinceLastShoot > delayShoot && canFire) { switch (selectedShot) { case 1: bulletFactory.createBullet(BulletType.player1, shotspawn.transform.position); decreaseEnergy(costShot1); break; case 2: bulletFactory.createBullet(BulletType.player2a, shotspawn.transform.position); bulletFactory.createBullet(BulletType.player2b, shotspawn.transform.position); decreaseEnergy(costShot2); break; default: bulletFactory.createBullet(BulletType.player3, shotspawn.transform.position); decreaseEnergy(costShot3); break; } timeSinceLastShoot = 0; } } slider.value = energy; } }
IEnumerator spawnShoot() { yield return(new WaitForSeconds(waitFirst)); while (true) { if (!ennemy_mover.isDead()) { bulletFactory.createBullet(BulletType.ennemy, shotspawn.transform.position); } yield return(new WaitForSeconds(waitBetween)); } }
// Update is called once per frame void FixedUpdate() { if (!phase1ended) { if (gameObject.transform.position.x > zoneWait1X) { Vector3 movement = Vector3.left * speed * Time.deltaTime; gameObject.transform.position = gameObject.transform.position + movement; if (gameObject.transform.position.x < zoneWait1X) { Vector3 pos = gameObject.transform.position; pos.x = zoneWait1X; gameObject.transform.position = pos; } } else if (shieldColor.a > 0) { shieldColor.a -= Time.deltaTime; if (shieldColor.a <= 0) { shieldColor.a = 0; invulnerability = false; timerShoot = 0; } shield.GetComponent <SpriteRenderer>().color = shieldColor; } else { timerShoot += Time.deltaTime; if (timerShoot > waitShootPhase1) { float angle; Vector3 axe; gameObject.transform.rotation.ToAngleAxis(out angle, out axe); if (axe.z > 0) { if (angle >= 0 && angle < 72) { bulletFactory.createBullet(BulletType.boss, shotspawn2.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn3.transform.position); } if (angle >= 72 && angle < 140) { bulletFactory.createBullet(BulletType.boss, shotspawn3.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn4.transform.position); } if (angle >= 140) { bulletFactory.createBullet(BulletType.boss, shotspawn4.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn5.transform.position); } } else if (axe.z < 0) { if (angle >= 143) { bulletFactory.createBullet(BulletType.boss, shotspawn4.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn5.transform.position); } if (angle < 143 && angle >= 72) { bulletFactory.createBullet(BulletType.boss, shotspawn5.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn1.transform.position); } if (angle < 72 && angle >= 0) { bulletFactory.createBullet(BulletType.boss, shotspawn1.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn2.transform.position); } } timerShoot = 0f; } } } else if (!phase2ended) { if (!prephase2ended) { if (shieldColor.a < 1) { shieldColor.a += Time.deltaTime; if (shieldColor.a > 1) { shieldColor.a = 1; prephase2ended = true; } shield.GetComponent <SpriteRenderer>().color = shieldColor; } else { prephase2ended = true; } } else if (gameObject.transform.position.y < zoneWait2Y) { Vector3 movement = Vector3.up * speed * Time.deltaTime; gameObject.transform.position = gameObject.transform.position + movement; if (gameObject.transform.position.y > zoneWait2Y) { Vector3 pos = gameObject.transform.position; pos.y = zoneWait2Y; gameObject.transform.position = pos; } } else if (shieldColor.a > 0) { shieldColor.a -= Time.deltaTime; if (shieldColor.a <= 0) { shieldColor.a = 0; invulnerability = false; timerShoot = 0; } shield.GetComponent <SpriteRenderer>().color = shieldColor; } else { timerShoot += Time.deltaTime; if (timerShoot > waitShootPhase2) { ennemyFactory.createEnnemy(); /* * Vector3 pos = gameManager.getSpawnEnnemyPosition(); * Instantiate(ennemy, pos, Quaternion.identity);*/ timerShoot = 0f; } } } else if (!phase3ended) { if (!prephase3ended) { if (shieldColor.a < 1) { shieldColor.a += Time.deltaTime; if (shieldColor.a > 1) { shieldColor.a = 1; prephase3ended = true; } shield.GetComponent <SpriteRenderer>().color = shieldColor; } else { prephase3ended = true; } } else if (gameObject.transform.position.y > zoneWait3Y) { Vector3 movement = Vector3.down * speed * Time.deltaTime; gameObject.transform.position = gameObject.transform.position + movement; if (gameObject.transform.position.y < zoneWait3Y) { Vector3 pos = gameObject.transform.position; pos.y = zoneWait3Y; gameObject.transform.position = pos; } } else if (shieldColor.a > 0) { shieldColor.a -= Time.deltaTime; if (shieldColor.a <= 0) { shieldColor.a = 0; invulnerability = false; timerShoot = 0; } shield.GetComponent <SpriteRenderer>().color = shieldColor; } else { timerShoot += Time.deltaTime; if (timerShoot > waitShootPhase3) { waitShootPhase3Count++; bulletFactory.createBullet(BulletType.boss, shotspawn1.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn2.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn3.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn4.transform.position); bulletFactory.createBullet(BulletType.boss, shotspawn5.transform.position); timerShoot = 0f; if (waitShootPhase3Count >= 5) { ennemyFactory.createEnnemy(); /* * Vector3 pos = gameManager.getSpawnEnnemyPosition(); * Instantiate(ennemy, pos, Quaternion.identity);*/ waitShootPhase3Count = 0; } } } } else { if (explosion.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.99f) { GameObject.FindGameObjectWithTag("gameManager").GetComponent <gameManager>().endGame(true); gameObject.GetComponent <destroy>().destroyObject(); } else if (explosion.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.3f) { gameObject.GetComponent <SpriteRenderer>().enabled = false; if (!powerUpPoped) { Instantiate(powerUp1, gameObject.transform.position + Vector3.up, Quaternion.identity); Instantiate(powerUp2, gameObject.transform.position + Vector3.down, Quaternion.identity); Instantiate(powerUp3, gameObject.transform.position + Vector3.left, Quaternion.identity); Instantiate(powerUp4, gameObject.transform.position + Vector3.right, Quaternion.identity); powerUpPoped = true; } } } }