Esempio n. 1
0
    void StraightShot()
    {
        GameObject Bullet;

        Bullet = (Instantiate(bulletprefab, transform.position, transform.rotation)) as GameObject;

        GameObject Bullet2;

        Bullet2 = (Instantiate(bulletprefab, transform.position, transform.rotation)) as GameObject;

        Bullet2.GetComponent <Rigidbody2D>().transform.Translate(new Vector3(1, 0, 0));

        GameObject Bullet3;

        Bullet3 = (Instantiate(bulletprefab, transform.position, transform.rotation)) as GameObject;

        Bullet3.GetComponent <Rigidbody2D>().transform.Translate(new Vector3(-1, 0, 0));



        //Bullet.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, bullet_speed*Time.deltaTime));

        //Bullet.transform.Translate(Vector2(0, bullet_speed));

        //Rigidbody Bullet = (Rigidbody)Instantiate(bulletprefab, transform.position + transform.forward, transform.rotation);
        //Bullet.GetComponent<Rigidbody2D>().AddForce(transform.forward * bullet_speed, ForceMode2D.Impulse);

        Destroy(Bullet, 1);

        Destroy(Bullet2, 1);

        Destroy(Bullet3, 1);
    }
Esempio n. 2
0
    void Shoot()
    {
        GameObject Bullet;
        GameObject Bullet2;
        GameObject Bullet3;
        GameObject Bullet4;
        GameObject Bullet5;

        BulletPhase = Random.Range(1, 6);

        switch (BulletPhase)
        {
        case 1:
            // Create projectile
            Bullet = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);     // Middle

            // Slow bullets
            Bullet.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            break;

        case 2:
            // Create projectile
            Bullet  = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Left
            Bullet2 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Right

            // Spawn bullets apart by set degrees
            Bullet.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, 0.5f, 0f));
            Bullet2.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, -0.5f, 0f));

            // Slow bullets
            Bullet.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet2.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            break;

        case 3:
            // Create projectile
            Bullet  = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Left
            Bullet2 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Middle
            Bullet3 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Right

            // Spawn bullets apart by set degrees
            Bullet.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, 0.5f, 0f));
            Bullet3.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, -0.5f, 0f));

            // Slow bullets
            Bullet.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet2.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet3.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            break;

        case 4:
            // Create projectile
            Bullet  = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Upper Left
            Bullet2 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Left
            Bullet3 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Right
            Bullet4 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Upper Right

            // Spawn bullets apart by set degrees
            Bullet.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, 0.6f, 0f));    // Upper Left
            Bullet2.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, 0.3f, 0f));   // Left
            Bullet3.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, -0.3f, 0f));  // Right
            Bullet4.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, -0.6f, 0f));  // Upper Right

            // Slow bullets
            Bullet.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet2.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet3.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet4.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            break;

        case 5:
            // Create projectile
            Bullet  = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Upper Left
            Bullet2 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Left
            Bullet3 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Middle
            Bullet4 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Right
            Bullet5 = Instantiate(Projectile, FirePoint.transform.position, transform.rotation);    // Upper Right

            // Spawn bullets apart by set degrees
            Bullet.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, 0.9f, 0f));    // Upper Left
            Bullet2.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, 0.5f, 0f));   // Left
            Bullet4.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, -0.5f, 0f));  // Right
            Bullet5.GetComponent <S_Bullet>().ChangeBulletDirection(new Vector3(1f, -0.9f, 0f));  // Upper Right

            // Slow bullets
            Bullet.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet2.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet3.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet4.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            Bullet5.GetComponent <S_Bullet>().SetBulletSpeed(BulletSpeed, 5f);
            break;

        default:
            Debug.Log("Bullet Phase not found");
            break;
        }
    }