Example #1
0
    /**********************************************
    **                                           **
    **              GESTION DES TIRS             **
    **                                           **
    ***********************************************/

    private void Update()
    {
        // bool fire1 = Input.GetButton("Fire1");
        // bool fire2 = Input.GetButton("Fire2");
        if (alive)
        {
            if (Input.GetButton("Fire1") && Time.time > nextFire)
            {
                nextFire = Time.time + fireRate;

                shotSound.Play();

                if (numberOfShots == 1)
                {
                    Instantiate(shot, shotSpawnCentre.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                }
                else if (numberOfShots == 2)
                {
                    Instantiate(shot, shotSpawnDroite.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                    Instantiate(shot, shotSpawnGauche.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                }
                else if (numberOfShots == 3)
                {
                    Instantiate(shot, shotSpawnDroite.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                    Instantiate(shot, shotSpawnCentre.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                    Instantiate(shot, shotSpawnGauche.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                }

                if (numberOfSatelittes == 1)
                {
                    Instantiate(shot, shotSpawnSat1.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                }
                else if (numberOfSatelittes == 2)
                {
                    Instantiate(shot, shotSpawnSat1.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                    Instantiate(shot, shotSpawnSat2.position, Quaternion.Euler(0.0f, 0.0f, 90.0f));
                }
            }

            if (numberOfBombs > 0)
            {
                if (Input.GetButtonUp("Fire2") && Time.time > nextBomb)
                {
                    nextBomb = Time.time + bombRate;

                    bombSound.Play();

                    numberOfBombs--;

                    Camera.main.GetComponent <Screenshake>().startShaking(0.8f);

                    foreach (EnemyScript enemy in FindObjectsOfType <EnemyScript>())
                    {
                        enemy.Die();
                    }

                    foreach (TorusBehaviour torus in FindObjectsOfType <TorusBehaviour>())
                    {
                        torus.Die();
                    }

                    foreach (GameObject minTor in GameObject.FindGameObjectsWithTag("MiniTorus"))
                    {
                        Destroy(minTor);
                    }

                    BossBehaviour boss = FindObjectOfType <BossBehaviour>();

                    if (boss != null)
                    {
                        boss.takeHit(bombDamage);
                    }
                }
            }
        }
    }