Exemple #1
0
    void ShootGun()
    {
        m_canShoot = false;
        //nextFire = Time.time + fireRate;


        RaycastHit hit;

        //Debug.Log("hit shoot");
        if (Physics.Raycast(GunTransform.position, GunTransform.forward, out hit, range))
        {
            Enemy enemy = hit.collider.GetComponent <Enemy>();
            //StartCoroutine(ShotEffect());
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(bulletPrefab, firePoint.transform.position, firePoint.transform.rotation) as GameObject;
            //Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);
            Rigidbody Temporty_RigidBody;
            Temporty_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
            Temporty_RigidBody.AddRelativeForce(-Vector3.forward * Bullet_Forward_Force);
            Destroy(Temporary_Bullet_Handler, 2.0f);

            //GameObject bulletGo = (GameObject)Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
            //Bullet bullet = bulletGo.GetComponent<Bullet>();
            //bulletGo.GetComponent<Rigidbody>().velocity = bulletGo.transform.forward * 6;
            //Enemy enemy = hit.transform.GetComponent<Enemy>();

            if (enemy != null)
            {
                enemy.TakeDamage(damage);
            }
        }
    }
Exemple #2
0
    void Shoot()
    {
        if (Time.time > nextFire)
        {
            shoot.Play();
            nextFire = Time.time + fireRate;
            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) 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.left * 90);

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

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

            //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, 2.0f);
        }
    }
    void Update()
    {
        // if (Input.GetKeyDown("space"))
        if (/* isDragged &&  */ Time.time > nextFireBullet)
        {
            nextFireBullet = Time.time + FireRate;


            //The Bullet instantiation happens here.
            // "Kugel" schould be "EnemyBullet"
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Kugel, EnemyBulletSpawner.transform.position, EnemyBulletSpawner.transform.rotation) 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.left * 90);

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

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

            //Basic Clean Up, set the Bullets to self destruct after 10 Seconds
            // needs to get destroyed when hiting
            Destroy(Temporary_Bullet_Handler, 5.0f);
        }
    }
Exemple #4
0
    public void ammu()
    {
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
        //korjaa jos ammus hatullaa
        Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

        //työnnä ammusta
        Rigidbody Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody> ();
        Temporary_RigidBody.AddForce(transform.forward * speed);
        //tuhoa ammus
        Destroy(Temporary_Bullet_Handler, 2.0f);
        timeBtwShots = startTimeBtwShots;

        //suuliekki
        GameObject Temporary_Flare_Handler;

        Temporary_Flare_Handler = Instantiate(Flare, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
        Destroy(Temporary_Flare_Handler, 0.2f);

        Ammo--;
    }
    // Update is called once per frame
    void Update()
    {
        if (shoot == true && timer <= 0)
        {
            timer = fireRate;



            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, spawnPoint.transform.position, this.transform.rotation) as GameObject;

            GetComponent <AudioSource>().PlayOneShot(gunShot);

            //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.left * 90);

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

            //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
            Temporary_RigidBody.AddForce(transform.right * speed * Time.deltaTime);
        }
        else if (shoot == true)
        {
            timer -= 1 * Time.deltaTime;
        }
        else if (timer != 1)
        {
            timer = 1;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Space) && isFireCount < 5)
        {
            isFiring = true;

            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;

            Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

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

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

            //Basic Clean Up, set the Bullets to self destruct after 4 Second.
            Destroy(Temporary_Bullet_Handler, 4);
        }
        else if (isFireCount > 20)
        {
            isFiring    = false;
            isFireCount = 0;
        }
        else
        {
            isFiring = false;
        }
        isFireCount++;
    }
    public override void Fire()
    {
        AudioSource Audio = GetComponent <AudioSource>();

        Audio.PlayOneShot(ShotSound);
        //The Bullet instantiation happens here.
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) 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.left * 180);

        //Retrieve the Rigidbody component from the instantiated Bullet and control it.
        Rigidbody2D Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>();

        //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
        Temporary_RigidBody.AddForce((transform.right * transform.localScale.x) * Bullet_Forward_Force);
        //Temporary_RigidBody.AddForce(transform.right * Bullet_Forward_Force);
        //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, 3.0f);
    }
    void spawn()
    {
        //int randomHurdle = UnityEngine.Random.Range(0, hurdles.Length-1);
        GameObject Temporary_Bullet_Handler;
        int        randomHurdle = Random.Range(0, 11);
        float      xpos         = Random.Range(-1.2f, 1.2f);
        float      zpos         = Random.Range(15f, 20f);
        float      ypos         = 2.88f;


        int abol  = Random.Range(1, 10);
        int tabol = Random.Range(1, 10);

        if (abol * tabol < 10)
        {
            //1
            Vector3 hposition = new Vector3(xpos, ypos, player.position.z + zpos);
            Temporary_Bullet_Handler = Instantiate(hurdles[0], hposition, hurdles[0].transform.rotation);
            //2
            hposition = new Vector3(xpos + 1f, ypos, player.position.z + zpos);
            Temporary_Bullet_Handler = Instantiate(hurdles[1], hposition, hurdles[1].transform.rotation);
            //3
            hposition = new Vector3(xpos + 1, ypos - 1f, player.position.z + zpos);
            Temporary_Bullet_Handler = Instantiate(hurdles[2], hposition, hurdles[2].transform.rotation);
            //4
            hposition = new Vector3(xpos - 1, ypos - 1f, player.position.z + zpos);
            Temporary_Bullet_Handler = Instantiate(hurdles[3], hposition, hurdles[3].transform.rotation);
            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
            Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);
        }


        StartCoroutine(spawnHurdle());
    }
Exemple #9
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical   = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        rb.AddForce(movement * speed);



        //  joint.connectedBody = Esfera2.rigidbody;


        if (Input.GetKeyDown("space"))
        {
            // Bullet instantiation
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
            // what, from where y rotation

            //por si el pivot se seteo mal de esta manera lo corregimos
            Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

            //tell bullet to be pushed
            Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);

            Destroy(Temporary_Bullet_Handler, 10.0f);
        }
    }
Exemple #10
0
    void Update()
    {
        time += Time.deltaTime;

        if (time >= interpolationPeriod)
        {
            time = 0.0f;

            // execute block of code here
            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position + new Vector3(0.0f, 0.0f, 0.0f), Bullet_Emitter.transform.rotation) as GameObject;

            Temporary_Bullet_Handler.transform.Rotate(Vector3.forward * 100);

            Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90);
            Temporary_Bullet_Handler.transform.Rotate(Vector3.up * -10);

            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

            Temporary_RigidBody.AddForce(transform.up * Bullet_Up_Force);

            Destroy(Temporary_Bullet_Handler, 5.0f);
        }
    }
Exemple #11
0
        private void HandAttachedUpdate(Hand hand)
        {
            transform.localRotation = Quaternion.Euler(-90.0f, 0f, -90.0f);

            if (Input.GetMouseButtonDown(0) || hand.grabPinchAction.GetStateDown(hand.handType))
            {
                //The Bullet instantiation happens here.
                GameObject Temporary_Bullet_Handler;
                Temporary_Bullet_Handler = Instantiate(bullet, bulletEmiter.position, bulletEmiter.rotation) 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.left * 90);

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

                //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
                Temporary_RigidBody.AddForce(bulletEmiter.right * bulletForce);

                //play sound
                sound.volume = volumeShot;
                sound.Play();

                //Basic Clean Up, set the Bullets to self destruct after 10 Seconds, I am being VERY generous here, normally 3 seconds is plenty.
                IEnumerator coroutine;
                coroutine = DestroyBullet(Temporary_Bullet_Handler);
                StartCoroutine(coroutine);
            }
        }
Exemple #12
0
    // Update is called once per frame
    void Update()
    {
        //1. Fly up and down
        if (Time.time > startTime + travelTime)
        {
            //reverse travel direction
            ReverseDirection();
        }

        float currentTime = (Time.time - startTime) / travelTime;

        transform.position = Vector3.Lerp(originalPosition, destination, currentTime);

        if (Time.frameCount == frameCount)
        {
            frameCount += 40;
            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) 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.left * 90);

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

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

            //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, 10.0f);
        }
    }
Exemple #13
0
    void Update()
    {
        if (Input.GetKey(KeyCode.Mouse0) && Time.time > nextFire && ammoManager.CanFire())
        {
            nextFire = Time.time + fireRate;

            FireParticles();

            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) 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.left * 90);

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

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

            //Lower the ammo capacity
            ammoManager.Fire();

            //ammoImage.fillAmount -= 0.2f / ammo;

            Temporary_Bullet_Handler.GetComponent <BulletDamage>().Attacker("Player");

            //Basic Clean Up, set the Bullets to self destruct after 3 Seconds.
            Destroy(Temporary_Bullet_Handler, 6.0f);
        }
    }
Exemple #14
0
    public void Fire()
    {
        if (pCurrentAmmo > 0)
        {
            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(pBullet, pBarrel.transform.position, pBarrel.transform.rotation) as GameObject;

            //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package.
            Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

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

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

            //Subtract bullets from magazine.
            pCurrentAmmo--;

            pAmmo.text = pCurrentAmmo.ToString();

            //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, 10.0f);
        }
        else
        {
            Debug.Log("No bullets left!");
        }
    }
Exemple #15
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("s"))
        {
            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, BulletEmitter.transform.position, BulletEmitter.transform.rotation) 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.left * 90);

            //Retrieve the Rigidbody component from the instantiated Bullet and control it.

            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

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

            //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, 10.0f);

            RaycastHit hit;
            Ray        ray = new Ray(transform.position, transform.forward);
            if (Physics.Raycast(ray, out hit, 200f))
            {
                hit.transform.GetComponent <EnemyHealth>().RemoveHealth(enemyDamage);
            }
            else if (Physics.Raycast(ray, out hit, 300f))
            {
                hit.transform.GetComponent <BoarHealth>().RemoveHealth(enemyDamage);
            }
        }
    }
Exemple #16
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            Shoot();

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

            //Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody> ();

            Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);

            Destroy(Temporary_Bullet_Handler, 0.8f);
        }

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            AudioSource audio = GetComponent <AudioSource> ();
            audio.Play();
        }
    }
Exemple #17
0
    void GunShoot()
    {
        CurrentAmmo          = CurrentAmmo - 1;
        CurrentAmmoText.text = CurrentAmmo.ToString();
        //Ump.AddForce(-1, 1, AddedRecoil, ForceMode.Impulse);
        muzzleflash.Play();

        int ShotNo = Random.Range((int)1, (int)4);

        if (ShotNo == 1)
        {
            PlayShot1();
        }
        if (ShotNo == 2)
        {
            PlayShot2();
        }
        if (ShotNo == 3)
        {
            PlayShot3();
        }

        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
        Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90);
        Rigidbody Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
        Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);

        Destroy(Temporary_Bullet_Handler, 10.0f);
    }
Exemple #18
0
    void Fire()
    {
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler = Instantiate(Bullet, Barrel.transform.position, Barrel.transform.rotation) 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.
        //don't change this or the bullets will fly up/to the side
        Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 0);

        //Retrieve the Rigidbody component from the instantiated Bullet and control it.
        Rigidbody Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

        //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
        Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);
        //don't correct this
        //Temporary_RigidBody.AddForce(transform.up * Bullet_Forward_Force);

        //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, 2.0f);

        //  yield WaitForSeconds(5);
    }
    void Update()
    {
        int speed = 10000;
        var q     = Quaternion.LookRotation(target.position - transform.position);

        transform.rotation = Quaternion.RotateTowards(transform.rotation, q, speed * Time.deltaTime);

        if (shotActive == true && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.x > transform.position.x - 700 && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.x < target.position.x + 7000 && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.z > target.position.z - 700 && GameObject.Find("Player").GetComponent <TrackPlayerLocation>().player.transform.position.z < target.position.z + 700)
        {
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
            Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90);
            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
            Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);
            Destroy(Temporary_Bullet_Handler, 4);
            shotActive = false;
        }

        if (shotActive == false)
        {
            if (shootCount < 40)
            {
                shootCount++;
            }
            else
            {
                shotActive = true;
                shootCount = 0;
            }
        }
    }
Exemple #20
0
    void Shoot()
    {
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

            Target target = hit.transform.GetComponent <Target>();
            if (target != null)
            {
                target.takeDamage(damage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }

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

            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

            Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);

            Destroy(Temporary_Bullet_Handler, 5.0f);
        }
    }
    void Update()
    {
        if (activated)
        {
            /*  Firing Logic  */
            lullCounter++;
            if (lullCounter > LullPeriod)
            {
                lullCounter = 0;
                isFiring    = !isFiring;
            }
            if (isFiring)
            {
                firingCounter++;
                if (firingCounter > FiringPeriod)
                {
                    source.clip = bulletAudio;
                    source.Play();
                    firingCounter = 0;
                    //The Bullet instantiation happens here.
                    GameObject Temporary_Bullet_Handler;
                    Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;

                    //Retrieve the Rigidbody component from the instantiated Bullet and control it.
                    Rigidbody2D Temporary_RigidBody;
                    Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>();

                    //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
                    Temporary_RigidBody.AddForce(Vector2.left * Bullet_Forward_Force);

                    //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, 5.0f);
                }

                /*  Bob Logic  */
                bobCounter++;
                if (bobCounter > BobPeriod)
                {
                    /*  Reset  */
                    bobCounter = 0;

                    if (bobUp)
                    {
                        bobState++;
                        parentScalar.localScale += new Vector3(0f, 0.025f, 0f);
                    }
                    else
                    {
                        bobState--;
                        parentScalar.localScale -= new Vector3(0f, 0.025f, 0f);
                    }
                    if (bobState == 3 || bobState == 0)
                    {
                        bobUp = !bobUp;
                    }
                }
            }
        }
    }
    // Update is called once per frame
    public void Update()
    {
        StartCoroutine(FindRecoil());

        if (Arrows <= 0)
        {
            Arrows = 0;
            SetCountAmmo();
            AmmoShot = false;
        }
        if (Arrows <= 10)
        {
            ArrowAmmo.color = new Color(Mathf.Sin(Time.time * 10), 0f, 0f, 1.0f);
        }
        else if (Arrows >= 11)
        {
            ArrowAmmo.color = new Color(1f, 1f, 1f, 1f);
        }


        if (Time.time > nextFire && AmmoShot)
        {
            ArrowObject.SetActive(true);
        }
        else
        {
            ArrowObject.SetActive(false);
        }
        if (Input.GetMouseButton(0) && Time.time > nextFire && AmmoShot == true || Input.GetAxisRaw("Attack") == -1 && Time.time > nextFire && AmmoShot == true)
        {
            Arrows -= 1;
            Rigidbody  Temporary_RigidBody;
            GameObject Temporary_Bullet_Handler;
            recoilComponent.StartRecoil(0.1f, -3f, 10f);
            nextFire = Time.time + fireRate;
            audioSrc.PlayOneShot(shoot);

            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
            Temporary_Bullet_Handler.transform.Rotate(Vector3.left);

            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
            Temporary_RigidBody.AddForce(CameraPosition.transform.forward * Bullet_Forward_Force);
            Destroy(Temporary_Bullet_Handler, 5.0f);
            SetCountAmmo();
        }

        if (whiteScreenFlashEnabled == true)
        {
            whiteScreen.SetActive(true);
            whiteScreenFlashTimer -= Time.deltaTime;
        }
        if (whiteScreenFlashTimer <= 0)
        {
            whiteScreen.SetActive(false);
            whiteScreenFlashEnabled = false;
            whiteScreenFlashTimer   = whiteScreenFlashTimerStart;
        }
    }
    public void MakeShoot()
    {
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler = Instantiate(bullet, bullet_Spawner.transform.position, bullet_Spawner.transform.rotation) as GameObject;

        Temporary_Bullet_Handler.GetComponent <Rigidbody>().AddRelativeForce(Vector3.forward * bullet_Impulse, ForceMode.Impulse);
        Temporary_Bullet_Handler.GetComponent <Bullet>().SetImprovements(damage, velocityBullet, rateAOE);
    }
Exemple #24
0
    private void FixedUpdate()
    {
        SpottedTimer += 1 * Time.deltaTime;
        timer        += 1 * Time.deltaTime;
        if (WalkerStart == true)
        {
            m_NavMeshAgent.SetDestination(m_StartPoint.position);
        }
        if (WalkerDuring == true)
        {
            if (SpottedTimer >= 5)
            {
                m_NavMeshAgent.SetDestination(m_StartPoint.position);
                SpottedTimer = 0;
                WalkerDuring = false;
                WalkerStart  = true;
            }
        }
        Vector3 targetDir = m_Target.position - transform.position;

        float angleToPlayer = (Vector3.Angle(targetDir, transform.forward));

        Vector3 Direction = (m_Target.position - transform.position).normalized;

        if (Physics.Raycast(transform.position, Direction, out m_RayHit, 15f))
        {
            if (m_RayHit.collider.tag == "Player" && angleToPlayer >= -60 && angleToPlayer <= 60)
            {
                m_NavMeshAgent.SetDestination(m_Target.position);
                WalkerStart = false;
                if (Distance(transform.position, m_Target.position) < 15f)
                {
                    if (timer >= 1)
                    {
                        GameObject Temporary_Bullet_Handler;
                        Temporary_Bullet_Handler = Instantiate(Kogel, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;

                        Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

                        Rigidbody Temporary_RigidBody;
                        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

                        Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);

                        Destroy(Temporary_Bullet_Handler, 25f);
                        timer = 0;
                    }
                }
            }
            else
            {
                WalkerDuring = true;
            }
        }
        Debug.DrawRay(transform.position, Direction * 15f, Color.red);
    }
    void Update()
    {
        distFromStart = transform.position.x - _originalPosition.x;

        if (isGoingLeft)
        {
            // If gone too far, switch direction
            if (distFromStart < -distance)
            {
                SwitchDirection();
            }

            _transform.Translate(-velocity.x * Time.deltaTime, 0, 0);
        }
        else
        {
            // If gone too far, switch direction
            if (distFromStart > distance)
            {
                SwitchDirection();
            }

            _transform.Translate(velocity.x * Time.deltaTime, 0, 0);
        }
        firingCounter++;
        if (firingCounter > 75)
        {
            firingCounter = 0;

            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) 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.left * 90);

            //Retrieve the Rigidbody component from the instantiated Bullet and control it.
            Rigidbody2D Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>();

            //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
            if (isGoingLeft)
            {
                Temporary_RigidBody.AddForce(Vector2.left * Bullet_Forward_Force);
            }
            else
            {
                Temporary_RigidBody.AddForce(Vector2.right * Bullet_Forward_Force);
            }

            //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, 5.0f);
        }
    }
Exemple #26
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        //Debug.Log ("We have a collision here!");
        if (coll.gameObject)
        {
            if (coll.gameObject.layer == 10)               // Player's layer
            {
                gameObject.AddComponent <AudioSource>().PlayOneShot(rozszczepienieSound);
                gameObject.layer = 11;
                int degree_multiplier = 1;
                if (!BulletBody.flipX)
                {
                    degree_multiplier = 3;
                }
                BulletBody.flipX = true;
                GameObject Temporary_Bullet_Handler;
                Temporary_Bullet_Handler = Instantiate(gameObject, GetComponent <Collider2D> ().transform.position, transform.rotation) 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.layer = 11;
                //Retrieve the Rigidbody component from the instantiated Bullet and control it.
                Rigidbody2D Temporary_RigidBody;
                Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D> ();
                Destroy(Temporary_Bullet_Handler, 10.0f);                  // destruct after 10 seconds
                Temporary_RigidBody.AddForce(Quaternion.Euler(0, 0, -45 * degree_multiplier) * -gameObject.transform.right * GlobalVariable.Instance.BulletForwardForce);
                GetComponent <Rigidbody2D> ().velocity = new Vector2(0, 0);
                GetComponent <Rigidbody2D> ().AddForce(Quaternion.Euler(0, 0, 45 * degree_multiplier) * -gameObject.transform.right * GlobalVariable.Instance.BulletForwardForce);
                Destroy(gameObject, 10.0f);
                Vector3 rot = new Vector3(0, 0, 1);
                transform.RotateAround(rot, Mathf.Deg2Rad * 45 * degree_multiplier);
                Temporary_Bullet_Handler.transform.RotateAround(rot, Mathf.Deg2Rad * -45 * degree_multiplier);
                GlobalVariable.Instance.playerHealth -= 5;

                Temporary_Bullet_Handler.SendMessage("SetShooter", Shooter);
            }
            else if (coll.gameObject.layer == 9)                 // enemy
            {
                if (coll.gameObject != Shooter)
                {
                    coll.gameObject.SendMessage("OnDamage", gameObject);
                }
                Destroy(gameObject);                      // bullet does as well
            }
            else if (coll.gameObject.layer == 13)         // platform
            {
                Destroy(gameObject);
            }
            else if (coll.gameObject.layer == 14 && gameObject.layer == 11)                 // Ziomek
            {
                coll.gameObject.SendMessage("OnDamage");
                Destroy(gameObject);
            }
        }
    }
Exemple #27
0
    void shootWithIntervals()
    {
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
        Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);
        Rigidbody Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
        Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);
        Destroy(Temporary_Bullet_Handler, 0.1f);
    }
Exemple #28
0
    public void Shoot()
    {
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler     = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
        Temporary_Bullet_Handler.tag = "Bullet";
        Rigidbody2D Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>();
        Temporary_RigidBody.AddForce(transform.forward + transform.TransformVector(0, 300, 0));
        Destroy(Temporary_Bullet_Handler, 7.0f);
    }
Exemple #29
0
    void Update()
    {
        distFromStart = transform.position.x - _originalPosition.x;

        if (isGoingLeft)
        {
            // If gone too far, switch direction
            if (distFromStart < -distance)
            {
                SwitchDirection();
            }

            _transform.Translate(-velocity.x * Time.deltaTime, 0, 0);
        }
        else
        {
            // If gone too far, switch direction
            if (distFromStart > distance)
            {
                SwitchDirection();
            }

            _transform.Translate(velocity.x * Time.deltaTime, 0, 0);
        }

        // Firing logic
        firingCounter++;
        if (firingCounter > firingPeriod)
        {
            bulletAudioSource.Play();
            firingCounter = 0;

            //The Bullet instantiation happens here.
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
            Physics2D.IgnoreCollision(Temporary_Bullet_Handler.GetComponent <Collider2D>(), GetComponent <Collider2D>());

            //Retrieve the Rigidbody component from the instantiated Bullet and control it.
            Rigidbody2D Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>();

            Vector3 playerPos = GameObject.Find("Player").transform.position;
            Vector3 bulletVec = playerPos - transform.position;
            bulletVec.Normalize();

            //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
            Temporary_RigidBody.AddForce(bulletVec * Bullet_Forward_Force);

            //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, 2.0f);
        }
    }
    void Shoot()
    {
        GameObject Temporary_Bullet_Handler;

        Temporary_Bullet_Handler      = Instantiate(bulletPrefab, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
        Temporary_Bullet_Handler.name = Temporary_Bullet_Handler.name.Substring(0, Temporary_Bullet_Handler.name.Length - 7);
        Temporary_Bullet_Handler.transform.Rotate(Vector3.right * 90);
        Rigidbody Temporary_RigidBody;

        Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();
        Temporary_RigidBody.AddForce(transform.forward * bulletSpeed * bulletWay);
        Destroy(Temporary_Bullet_Handler, 0.8f);
    }