Пример #1
0
    void Update()
    {
        //Look at the player
        transform.LookAt(player);


        Rigidbody TempBody;

        //"push" it so it goes, no gravity
        TempBody = gameObject.GetComponent <Rigidbody>();
        count   += (1 * Time.deltaTime);

        if (count > 1)
        {
            //TempBody.AddForce(transform.up * 100);
            TempBody.AddForce(transform.forward * 800);
            count = 0;
        }
        //TempBody.AddForce(transform.forward * 10);

        //Calculate distance between player
        //float distance = Vector3.Distance(transform.position, player.position);
        //If the distance is smaller than the walkingDistance
        //if (distance < walkingDistance)
        // {
        //Move the enemy towards the player with smoothdamp
        //transform.position = Vector3.SmoothDamp(transform.position, player.position, ref smoothVelocity, smoothTime);
        //}
    }
Пример #2
0
    void FixedUpdate()
    {
        //basic shot
        if (canshootint >= .5F)
        {
            canshootbool = true;
        }
        canshootint += Time.deltaTime;
        if (canshootbool)
        {
            //create hte bullet object
            GameObject Temp;
            //make it in the scene
            Temp = Instantiate(Bullet, gameObject.transform.position + new Vector3(0, 1, 0), gameObject.transform.rotation) as GameObject;
            //rotate for simple fire
            Temp.transform.Rotate(Vector3.left * 90);
            //give it a rigid body
            Rigidbody TempBody;
            //"push" it so it goes, no gravity
            TempBody = Temp.GetComponent <Rigidbody>();
            TempBody.AddForce(transform.forward * Force);
            Destroy(Temp, 1.0f);

            canshootbool = false;
            canshootint  = 0F;
        }
    }
Пример #3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(1) && currentGrenades > 0)
     {
         currentGrenades--;
         //Instantiate the bullet and rotate.
         GameObject TemporaryBullet;
         TemporaryBullet = Instantiate(Grenade, BulletEmitter.transform.position, BulletEmitter.transform.rotation) as GameObject;
         //Get the Rigidbody component from the instantiated Bullet and give the bullet forward momentum.
         Rigidbody TempBody;
         TempBody = TemporaryBullet.GetComponent <Rigidbody>();
         TempBody.AddForce(transform.forward * BulletForce);
     }
 }
Пример #4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown("f"))
     {
         if (mineCount <= 0)
         {
             return;
         }
         mineCount--;
         //Instantiate the Mine and rotate.
         GameObject TemporaryBullet;
         TemporaryBullet = Instantiate(Mines, BulletEmitter.transform.position, BulletEmitter.transform.rotation) as GameObject;
         //Get the Rigidbody component from the instantiated Mine and give the bullet Mine momentum.
         Rigidbody TempBody;
         TempBody = TemporaryBullet.GetComponent <Rigidbody>();
         TempBody.AddForce(transform.forward * BulletForce);
     }
 }
Пример #5
0
    void FixedUpdate()
    {
        if (isapois)
        {
            //basic shot
            if (canshootint >= .5f)
            {
                canshootbool = true;
            }
            canshootint += Time.deltaTime;
            if (canshootbool)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, gameObject.transform.position + new Vector3(0, 4, 0), gameObject.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(new Vector3(Random.Range(-1000f, 1000f), Random.Range(500f, 1000f), Random.Range(-1000f, 1000f)));
                //Destroy(Temp, 1.0f);

                canshootbool = false;
                canshootint  = 0F;
            }
        }
        if (isafire)
        {
            //basic shot
            if (canshootint >= .2F)
            {
                canshootbool = true;
            }
            canshootint += Time.deltaTime;
            if (canshootbool)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, gameObject.transform.position + new Vector3(0, -3, 0), gameObject.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(new Vector3(Random.Range(-1000f, 1000f), 0, Random.Range(-1000f, 1000f)));
                //Destroy(Temp, 1.0f);

                canshootbool = false;
                canshootint  = 0F;
            }
        }
        if (isajumpy)
        {
            if (canjumpint >= 2F)
            {
                canjumpbool = true;
            }
            canjumpint += Time.deltaTime;
            if (canjumpbool)
            {
                Rigidbody temp = gameObject.GetComponent <Rigidbody>();
                temp.AddForce(transform.up * 1000);
                canjumpbool = false;
                canjumpint  = 0;

                //Debug.Log("jump ");
            }
        }
        if (isafly)
        {
            //basic shot
            if (canshootint >= 1F)
            {
                canshootbool = true;
            }
            canshootint += Time.deltaTime;
            if (canshootbool)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, gameObject.transform.position + new Vector3(0, -4, 0), gameObject.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force * 2);
                Destroy(Temp, 2.0f);

                canshootbool = false;
                canshootint  = 0F;
            }
        }
        if (isashooter)
        {
            //basic shot
            if (canshootint >= .5F)
            {
                canshootbool = true;
            }
            canshootint += Time.deltaTime;
            if (canshootbool)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, gameObject.transform.position + new Vector3(0, 1, 0), gameObject.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force);
                Destroy(Temp, 1.0f);

                canshootbool = false;
                canshootint  = 0F;
            }
        }
        if (isalaserman)
        {
            //basic shot
            if (canshootint >= 4F)
            {
                canshootbool = true;
            }
            canshootint += Time.deltaTime;
            if (canshootbool)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, gameObject.transform.position + new Vector3(0, 1, 0), gameObject.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                //Rigidbody TempBody;
                //"push" it so it goes, no gravity
                // TempBody = Temp.GetComponent<Rigidbody>();
                // TempBody.AddForce(transform.forward * Force);
                Destroy(Temp, 3.0f);

                canshootbool = false;
                canshootint  = 0F;
            }
        }
    }
Пример #6
0
    void Update()
    {
        //basic shot
        if (canshootint >= 1F)
        {
            canshootbool = true;
        }
        canshootint += Time.deltaTime;

        //mode change
        if (Input.GetKeyDown(KeyCode.J))
        {
            if (mode != 0)
            {
                mode--;
            }
        }
        if (Input.GetKeyDown(KeyCode.K))
        {
            if (mode != 2)
            {
                mode++;
            }
        }
        type.text = types[mode];

        // type 0
        if (Input.GetKeyDown(KeyCode.U) && canshootbool)
        {
            if (mode == 0)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force);
                Destroy(Temp, 1.0f);
            }
            if (mode == 1)
            {
                //create hte bullet object
                GameObject Temp1;
                //make it in the scene
                Temp1 = Instantiate(FBullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp1.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp1.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force);
                Destroy(Temp1, 1.0f);
            }
            if (mode == 2)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(BBullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force);
                Destroy(Temp, 1.0f);
            }

            canshootbool = false;
            canshootint  = 0F;
        }
        //Fast and long range
        if (Input.GetKeyDown(KeyCode.I) && canshootbool)
        {
            if (mode == 0)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force * 3);
                Destroy(Temp, 1.0f);
            }
            if (mode == 1)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(FBullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force * 3);
                Destroy(Temp, 1.0f);
            }
            if (mode == 2)
            {
                //create hte bullet object
                GameObject Temp;
                //make it in the scene
                Temp = Instantiate(BBullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                //rotate for simple fire
                Temp.transform.Rotate(Vector3.left * 90);
                //give it a rigid body
                Rigidbody TempBody;
                //"push" it so it goes, no gravity
                TempBody = Temp.GetComponent <Rigidbody>();
                TempBody.AddForce(transform.forward * Force * 3);
                Destroy(Temp, 1.0f);
            }

            canshootbool = false;
            canshootint  = 0F;
        }
        //shotgun
        if (Input.GetKeyDown(KeyCode.O) && canshootbool)
        {
            if (mode == 0)
            {
                int        x = 0;
                GameObject Temp;
                for (; x < 3; x++)
                {
                    //make it in the scene
                    Temp = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                    //rotate for simple fire
                    Temp.transform.Rotate(Vector3.left * (60 + (30 * x)));
                    //give it a rigid body
                    Rigidbody TempBody;
                    //"push" it so it goes, no gravity
                    TempBody = Temp.GetComponent <Rigidbody>();
                    TempBody.AddForce(transform.forward * Force);
                    Destroy(Temp, .3f);

                    canshootbool = false;
                    canshootint  = 0F;
                }
                x = 0;
            }
            if (mode == 1)
            {
                int        x = 0;
                GameObject Temp;
                for (; x < 3; x++)
                {
                    //make it in the scene
                    Temp = Instantiate(FBullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                    //rotate for simple fire
                    Temp.transform.Rotate(Vector3.left * (60 + (30 * x)));
                    //give it a rigid body
                    Rigidbody TempBody;
                    //"push" it so it goes, no gravity
                    TempBody = Temp.GetComponent <Rigidbody>();
                    TempBody.AddForce(transform.forward * Force);
                    Destroy(Temp, .3f);

                    canshootbool = false;
                    canshootint  = 0F;
                }
                x = 0;
            }
            if (mode == 2)
            {
                int        x = 0;
                GameObject Temp;
                for (; x < 3; x++)
                {
                    //make it in the scene
                    Temp = Instantiate(BBullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
                    //rotate for simple fire
                    Temp.transform.Rotate(Vector3.left * (60 + (30 * x)));
                    //give it a rigid body
                    Rigidbody TempBody;
                    //"push" it so it goes, no gravity
                    TempBody = Temp.GetComponent <Rigidbody>();
                    TempBody.AddForce(transform.forward * Force);
                    Destroy(Temp, .3f);

                    canshootbool = false;
                    canshootint  = 0F;
                }
                x = 0;
            }
        }

        //circle

        /*
         * if (Input.GetKeyDown(KeyCode.P) && canshootbool)
         * {
         *  //create hte bullet object
         *  GameObject Temp;
         *  //make it in the scene
         *  //Temp = Instantiate(Big, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
         *  //rotate for simple fire
         *  Temp.transform.Rotate(Vector3.left * 90);
         *  //give it a rigid body
         *  Rigidbody TempBody;
         *  //"push" it so it goes, no gravity
         *  TempBody = Temp.GetComponent<Rigidbody>();
         *  TempBody.AddForce(transform.forward * Force);
         *  Destroy(Temp, 10.0f);
         *
         *  canshootbool = false;
         *  canshootint = 0F;
         * }*/
    }