private void genBullet(float force)
    {
        //The Bullet instantiation happens here.
        GameObject Temporary_Bullet_Handler_1;
        GameObject Temporary_Bullet_Handler_2;

        Temporary_Bullet_Handler_1 = Instantiate(Bullet, Bullet_Emitter_1.transform.position, Quaternion.Euler(90, 0, 0)) as GameObject;
        Temporary_Bullet_Handler_2 = Instantiate(Bullet, Bullet_Emitter_2.transform.position, Quaternion.Euler(90, 0, 0)) as GameObject;

        Rigidbody Temporary_RigidBody_1;

        Temporary_RigidBody_1 = Temporary_Bullet_Handler_1.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_2;

        Temporary_RigidBody_2 = Temporary_Bullet_Handler_2.GetComponent <Rigidbody>();

        //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
        Temporary_RigidBody_1.AddForce(transform.forward * force * 1000);
        Temporary_RigidBody_2.AddForce(transform.forward * force * 1000);

        Destroy(Temporary_Bullet_Handler_1, 4f);
        Destroy(Temporary_Bullet_Handler_2, 4f);

        InnerCounter = 0;
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler_1;
            GameObject Temporary_Bullet_Handler_2;

            Temporary_Bullet_Handler_1 = Instantiate(Bullet, Bullet_Emitter_1.transform.position, Quaternion.Euler(90, 0, 0)) as GameObject;
            Temporary_Bullet_Handler_2 = Instantiate(Bullet, Bullet_Emitter_2.transform.position, Quaternion.Euler(90, 0, 0)) as GameObject;

            //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package.
            //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh.
            //Temporary_Bullet_Handler.transform.Rotate(Vector3.forward);

            //Retrieve the Rigidbody component from the instantiated Bullet and control it.
            Rigidbody Temporary_RigidBody_1;
            Temporary_RigidBody_1 = Temporary_Bullet_Handler_1.GetComponent <Rigidbody>();

            Rigidbody Temporary_RigidBody_2;
            Temporary_RigidBody_2 = Temporary_Bullet_Handler_2.GetComponent <Rigidbody>();

            //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
            Temporary_RigidBody_1.AddForce(transform.forward * Bullet_Forward_Force * 1000);
            Temporary_RigidBody_2.AddForce(transform.forward * Bullet_Forward_Force * 1000);

            //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty.
            Destroy(Temporary_Bullet_Handler_1, 4f);
            Destroy(Temporary_Bullet_Handler_2, 4f);
        }
    }
Beispiel #3
0
    public void Shoot()
    {
        audioSource.clip = audioClip;
        audioSource.Play();
        //KOGELS SPAWNEN
        GameObject Temporary_kogel_handeler;

        Temporary_kogel_handeler = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        GameObject Temporary_kogel_handeler_1;

        Temporary_kogel_handeler_1 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        GameObject Temporary_kogel_handeler_2;

        Temporary_kogel_handeler_2 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        GameObject Temporary_kogel_handeler_3;

        Temporary_kogel_handeler_3 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        //KOGELS SPAWNEN (DIAGONAAL)
        GameObject Temporary_kogel_handeler_4;

        Temporary_kogel_handeler_4 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        GameObject Temporary_kogel_handeler_5;

        Temporary_kogel_handeler_5 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        GameObject Temporary_kogel_handeler_6;

        Temporary_kogel_handeler_6 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        GameObject Temporary_kogel_handeler_7;

        Temporary_kogel_handeler_7 = Instantiate(kogelPrefab, kogelspawn.transform.position, kogelspawn.transform.rotation) as GameObject;

        //KOGELS RIGIDBODY
        Rigidbody Temporary_RigidBody;

        Temporary_RigidBody = Temporary_kogel_handeler.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_1;

        Temporary_RigidBody_1 = Temporary_kogel_handeler_1.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_2;

        Temporary_RigidBody_2 = Temporary_kogel_handeler_2.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_3;

        Temporary_RigidBody_3 = Temporary_kogel_handeler_3.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_4;

        Temporary_RigidBody_4 = Temporary_kogel_handeler_4.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_5;

        Temporary_RigidBody_5 = Temporary_kogel_handeler_5.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_6;

        Temporary_RigidBody_6 = Temporary_kogel_handeler_6.GetComponent <Rigidbody>();

        Rigidbody Temporary_RigidBody_7;

        Temporary_RigidBody_7 = Temporary_kogel_handeler_7.GetComponent <Rigidbody>();

        //KOGELS BEWEGING
        Temporary_RigidBody.AddForce(new Vector3(-1, 0, 0) * kogelspeed);
        Temporary_RigidBody_1.AddForce(new Vector3(1, 0, 0) * kogelspeed);
        Temporary_RigidBody_2.AddForce(new Vector3(0, 0, -1) * kogelspeed);
        Temporary_RigidBody_3.AddForce(new Vector3(0, 0, 1) * kogelspeed);
        //KOGELS BEWEGING (DIAGONAAL)
        Temporary_RigidBody_4.AddForce(new Vector3(-1, 0, 1) * kogelspeed);
        Temporary_RigidBody_5.AddForce(new Vector3(1, 0, -1) * kogelspeed);
        Temporary_RigidBody_6.AddForce(new Vector3(-1, 0, -1) * kogelspeed);
        Temporary_RigidBody_7.AddForce(new Vector3(1, 0, 1) * kogelspeed);

        //KOGELS DESTROY
        Destroy(Temporary_kogel_handeler, 1.0f);
        Destroy(Temporary_kogel_handeler_1, 1.0f);
        Destroy(Temporary_kogel_handeler_2, 1.0f);
        Destroy(Temporary_kogel_handeler_3, 1.0f);
        Destroy(Temporary_kogel_handeler_4, 1.0f);
        Destroy(Temporary_kogel_handeler_5, 1.0f);
        Destroy(Temporary_kogel_handeler_6, 1.0f);
        Destroy(Temporary_kogel_handeler_7, 1.0f);
    }