void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            StartCoroutine(ShotEfect());
            Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
            RaycastHit hit;
            laserline.SetPosition(0, gunEnd.position);

            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserline.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();

                if (health != null)
                {
                    health.Damage(gunDamage);
                }

                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserline.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
    }
Esempio n. 2
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && nextFire > FireRate)
     {
         nextFire = 0;
         StartCoroutine(shotEffect());
         Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
         RaycastHit hit;
         if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
         {
             Shootable health = hit.collider.GetComponent <Shootable> ();
             laserLine.transform.LookAt(hit.point);
             var clone = Instantiate(laserEffect, hit.point, Quaternion.LookRotation(hit.normal));
             Destroy(clone.gameObject, 4);
             if (health != null)
             {
                 health.Damage(damage);
             }
             if (hit.rigidbody != null)
             {
                 hit.rigidbody.AddForce(-hit.normal * hitForce);
             }
         }
         else
         {
             laserLine.transform.LookAt(rayOrigin + (fpsCam.transform.forward * weaponRange));
         }
     }
     nextFire         += Time.deltaTime;
     laserEnergy.value = nextFire;
 }
    //void Update()

    public void Fire()
    {
        //if ((Input.GetMouseButton(0) != false || Input.GetAxisRaw("Right_Trigger") != 0) && Time.time > nextFire) //Fire1 = ctrl, jump = space
        if (Time.time > nextFire) //Fire1 = ctrl, jump = space
        {
            //GetMouseButtonDown is once per click, GetMouseButton checks every frame
            nextFire = Time.time + fireRate;
            StartCoroutine(ShotEffect());

            //Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); //gets exact center of fps cam
            //Vector3 rayOrigin = transform.forward;
            RaycastHit hit;

            laserLine.SetPosition(0, gunEnd.position);
            if (Physics.Raycast(transform.position, transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();
                if (health != null)
                {
                    health.Damage(gunDamage);
                }
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserLine.SetPosition(1, transform.position + (transform.forward * weaponRange));
            }
        }
    }
Esempio n. 4
0
    void DrawShoot(int index, int dmg)
    {
        StartCoroutine(ShotEffect(index));
        Vector3 realDirection  = fpsCam.transform.forward;
        Vector3 shootDirection = realDirection + new Vector3(
            Random.Range(-0.05f * index, 0.05f * index),
            Random.Range(-0.05f * index, 0.05f * index),
            Random.Range(-0.05f * index, 0.05f * index)
            );
        Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
        RaycastHit hit;

        linesRenderer[index].SetPosition(0, gunEnd.position);
        if (Physics.Raycast(rayOrigin, shootDirection, out hit, weaponRange))
        {
            linesRenderer[index].SetPosition(1, hit.point);
            Shootable shootableComponent = hit.collider.GetComponent <Shootable>();
            if (shootableComponent != null)
            {
                shootableComponent.Damage(dmg);
            }

            BossBehavior boosBehavior = hit.collider.GetComponent <BossBehavior>();
            if (boosBehavior != null)
            {
                boosBehavior.ReceiveDamage(dmg);
            }
        }
        else
        {
            linesRenderer[index].SetPosition(1, rayOrigin + (shootDirection * weaponRange));
        }
    }
Esempio n. 5
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("Hit" + collision.collider.name);
        Shootable shootable = collision.collider.gameObject.GetComponent <Shootable>();

        if (shootable)
        {
            shootable.Damage(Damage);
        }
        gameObject.SetActive(false);
    }
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Bullet") //|| other.gameObject.tag == "Shield")
     {
         Shootable health = other.gameObject.GetComponent <Shootable>();
         if (health != null)
         {
             health.Damage(gunDamage);
         }
     }
     Destroy(gameObject);
 }
 // Use this for initialisation
 void OnCollisionEnter(Collision other)
 {
     if ((other.gameObject.tag == "Enemy" && repulsed) || other.gameObject.tag == "Player" || other.gameObject.tag == "Bullet") //|| other.gameObject.tag == "Shield")
     {
         Shootable health = other.gameObject.GetComponent <Shootable>();
         if (health != null)
         {
             health.Damage(gunDamage);
         }
         //Debug.Log("Id of victim: " + other.gameObject.name + ", health = " + other.gameObject.GetComponent<Shootable>().currentHealth);
     }
     Destroy(gameObject);
 }
Esempio n. 8
0
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire && gunAmmo > 0)
        {
            nextFire = Time.time + fireRate;

            StartCoroutine(ShotEffect());

            Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

            RaycastHit hit;

            laserLine.SetPosition(0, gunEnd.position);

            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();

                if (health != null)
                {
                    health.Damage(gunDamage);
                }

                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
        if (Input.GetKeyDown(KeyCode.R) && ammo > 0)
        {
            if (ammo < 9)
            {
                gunAmmo = ammo;
                ammo    = 0;
                currentAmmo();
            }
            else
            {
                ammo    = gunAmmo + ammo - 9;
                gunAmmo = 9;
                currentAmmo();
            }
        }
    }
Esempio n. 9
0
 private void successfulShot(RaycastHit targetHit)
 {
     laserLine.SetPosition(1, targetHit.point);
     shotFXFront.transform.position = targetHit.point;
     shotFXBack.transform.position  = targetHit.point;
     if (targetHit.transform.tag == "Enemy")
     {
         shotFXBack.SetActive(true);
     }
     health = targetHit.collider.GetComponent <Shootable>();
     if (health != null)
     {
         health.Damage(gunDamage);
     }
     if (targetHit.rigidbody != null)
     {
         targetHit.rigidbody.AddForce(-targetHit.normal * hitForce);
     }
 }
    private IEnumerator ShotEffect()
    {
        //gunAudio.play();
        //anim.SetBool("Fire", true);
        side *= -1;
        if (side == 1)
        {
            anim.SetTrigger("Fire_Right");
            temp = gunEndRight;
        }
        else
        {
            anim.SetTrigger("Fire_Left");
            temp = gunEndLeft;
        }
        yield return(new WaitForSeconds(0.2f));

        laserLine.SetPosition(0, temp.position);
        if (Physics.Raycast(transform.position, transform.forward, out hit, weaponRange))
        {
            laserLine.SetPosition(1, hit.point);
            Shootable health = hit.collider.GetComponent <Shootable>();
            if (health != null)
            {
                health.Damage(gunDamage);
            }
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * hitForce);
            }
        }
        else
        {
            laserLine.SetPosition(1, transform.position + (transform.forward * weaponRange));
        }
        laserLine.enabled = true;
        yield return(shotDuration);

        laserLine.enabled = false;
        //anim.SetBool("Fire", false);
    }
Esempio n. 11
0
    void Update()
    {
        if (isReloading)
        {
            return;
        }
        currentAmmo = currentAmmo;
        muzzleFlash.Stop();
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            //shoot when button pressed and
            nextFire = Time.time + fireRate;
            currentAmmo--;
            shotText.GetComponent <Text> ().text = currentAmmo.ToString();
            muzzleFlash.Play();
            shootSound.Play();
            animator.SetBool("Shooting", true);
            StartCoroutine(ShotEffect());
            Vector3 rayOrigin = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            Debug.DrawRay(rayOrigin, cam.transform.forward * weaponRange, Color.red);
            RaycastHit hit;
            laserLine.SetPosition(0, gunEnd.position);

            if (Physics.Raycast(rayOrigin, cam.transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable> ();
                if (health != null)
                {
                    health.Damage(gunDamage);
                }
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
                GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impactGO, 1f);
            }

            else
            {
                laserLine.SetPosition(1, rayOrigin + (cam.transform.forward * weaponRange));
            }
            animator.SetBool("Shooting", false);
        }

//		if (currentAmmo <= 0) {
//			StartCoroutine (Reload ());
//			return;
//		}
        if (currentAmmo <= 0)
        {
            StartCoroutine(Reload());
            return;
        }
        if (Input.GetButtonUp("Fire2") && currentAmmo < 30)
        {
            StartCoroutine(Reload());
            return;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Time.time > nextCharge)
        {
            ChargeImage.SetActive(true);
        }
        if (Input.GetMouseButtonDown(1) && nextCharge < Time.time)
        {
            if (Time.time >= nextCharge)
            {
                ChargeImage.SetActive(true);
            }
            if (Physics.Raycast(transform.position, transform.forward, out hit, chargeRange) && hit.collider.tag == "Enemy")
            {
                StartCoroutine(StartCharge());
                hit.collider.GetComponent <Rigidbody>().velocity = Vector3.zero;
                //chargeField.transform.localScale = area;
                nextCharge = Time.time + chargeTimer;
                if (Time.time < nextCharge)
                {
                    ChargeImage.SetActive(false);
                }
                //Vector3 targetLocation = new Vector3(hit.point.x, 0, hit.point.z);
                targetHealth = hit.collider.GetComponent <Shootable>().currentHealth;
                health       = hit.collider.GetComponent <Shootable>();
                direction    = hit.point - transform.position;
                destination  = hit.point;
                dashed       = true;
                direction.Normalize();
                gameObject.GetComponent <Rigidbody>().AddForce((direction) * chargeSpeed);
                gameObject.GetComponent <PlayerMovement>().enabled = false;
                gameObject.GetComponent <GunController>().enabled  = false;
                if (hit.collider.GetComponent <EnemyScript>().knockedOut)
                {
                    damage = (int)(comboMultiplier * chargeAOEDamage);
                    //chargeField.transform.localScale = comboArea;
                }
                target = hit.collider.gameObject;
                gameObject.GetComponent <Collider>().enabled = false;
                //hit.collider.GetComponent<EnemyController>().Death();
                gameObject.GetComponent <GunController>().ammo = gameObject.GetComponent <GunController>().maxAmmo;
                //Debug.Log("Just Reloaded, ammo = " + gameObject.GetComponent<GunController>().ammo);
                //StartCoroutine(ChargeTarget(hit));
                oopsTimer = Time.time + 2;
            }
        }

        /*
         * if (transform.forward != direction && dashed)
         *  transform.forward = direction;
         */

        if (dashed && Time.time >= oopsTimer)
        {
            dashed = false;
            gameObject.GetComponent <PlayerMovement>().enabled = true;
        }

        if (Vector3.Distance(destination, transform.position) < 1 && dashed)
        {
            health.Damage(targetHealth);
            target.GetComponent <EnemyScript>().Die();
            StartCoroutine(EndCharge());
            gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
            colliders = Physics.OverlapSphere(transform.position, chargeAOE);
            gameObject.GetComponent <Collider>().enabled = true;
            foreach (Collider col in colliders)
            {
                try
                {
                    col.GetComponent <Shootable>().currentHealth -= damage;
                }
                catch
                {
                }
            }
            dashed = false;
            gameObject.GetComponent <PlayerMovement>().enabled = true;
            gameObject.GetComponent <GunController>().enabled  = true;
        }
    }
Esempio n. 13
0
    // Update is called once per frame
    void Update()
    {
        //commented movement
        moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
        moveVelocity = moveInput * moveSpeed;

        //Rotate with Mouse
        if (!useController)
        {
            Ray   cameraRay   = mainCamera.ScreenPointToRay(Input.mousePosition);
            Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
            float rayLength;

            if (groundPlane.Raycast(cameraRay, out rayLength))
            {
                Vector3 pointToLook = cameraRay.GetPoint(rayLength);
                Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);
                transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
            }
        }


        //Rotate with Controller
        if (useController)
        {
            Vector3 playerDirection = Vector3.right * Input.GetAxisRaw("Right_Horizontal") + Vector3.forward * Input.GetAxisRaw("Right_Vertical");
            if (playerDirection.sqrMagnitude > 0.0f)
            {
                transform.rotation = Quaternion.LookRotation(playerDirection, Vector3.up);
            }
        }

        if ((Input.GetMouseButton(0) || Input.GetAxisRaw("Right_Trigger") != 0) && Time.time > nextFire && !theShield.activeSelf) //Fire1 = ctrl, jump = space
        {
            //GetMouseButtonDown is once per click, GetMouseButton checks every frame
            nextFire = Time.time + fireRate;
            StartCoroutine(ShotEffect());

            //Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); //gets exact center of fps cam
            //Vector3 rayOrigin = transform.forward;
            laserLine.SetPosition(0, gunEnd.position);
            if (Physics.Raycast(transform.position, transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();
                if (health != null)
                {
                    health.Damage(gunDamage);
                }
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserLine.SetPosition(1, transform.position + (transform.forward * weaponRange));
            }
        }

        if (Input.GetMouseButtonDown(1) && nextCharge < Time.time)
        {
            if (Physics.Raycast(transform.position, transform.forward, out hit, weaponRange) && hit.collider.tag == "Enemy")
            {
                nextCharge = Time.time + chargeTimer;
                //Vector3 targetLocation = new Vector3(hit.point.x, 0, hit.point.z);
                int       targetHealth = hit.collider.GetComponent <Shootable>().currentHealth;
                Shootable health       = hit.collider.GetComponent <Shootable>();
                health.Damage(targetHealth);
                transform.position = hit.point;
                //StartCoroutine(ChargeTarget(hit));
            }
        }

        if (Input.GetAxisRaw("Left_Trigger") != 0 || Input.GetMouseButton(2))
        {
            if (!theShield.activeSelf && Time.time >= nextBlock)
            {
                nextBlock = Time.time + blockTimer;
                theGun.SetActive(false);
                theShield.SetActive(true);
                theShield.GetComponent <Shootable>().enabled       = true;
                theShield.GetComponent <BoxCollider>().enabled     = true;
                theShield.GetComponent <Shootable>().currentHealth = 10;
            }
        }

        if ((Time.time >= nextBlock && theShield.activeSelf) || (useController && Input.GetAxisRaw("Left_Trigger") == 0 && theShield.activeSelf || !useController && !Input.GetMouseButton(2) && theShield.activeSelf))
        {
            theShield.GetComponent <Shootable>().enabled   = false;
            theShield.GetComponent <BoxCollider>().enabled = false;
            theShield.SetActive(false);
            theGun.SetActive(true);
            Debug.Log("current block timer: " + nextBlock);
            nextBlock = Time.time + blockTimer;
            Debug.Log("next block timer: " + nextBlock);
        }

        if (gameObject.GetComponent <Shootable>().currentHealth <= 0)
        {
            theGun.SetActive(false);
            theShield.SetActive(false);
            gameObject.GetComponent <MeshRenderer>().enabled = false;
            gameObject.SetActive(false);
        }
    }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        progress     = 5f - (nextCharge - Time.time);
        slider.value = progress;
        if (Time.time > nextCharge)
        {
            ChargeImage.SetActive(true); progress = 5f;
        }
        if (Input.GetMouseButtonDown(1) && nextCharge < Time.time)
        {
            if (Time.time >= nextCharge)
            {
                ChargeImage.SetActive(true);
            }
            progress = 5f;

            hit = default(RaycastHit);

            Physics.Raycast(transform.position, transform.forward, out hitA, chargeRange);
            Physics.Raycast(transform.position + aimAssist, transform.forward, out hitB, chargeRange);
            Physics.Raycast(transform.position - aimAssist, transform.forward, out hitC, chargeRange);
            if (hitA.transform.tag == "Enemy" || hitB.transform.tag == "Enemy" || hitC.transform.tag == "Enemy")
            {
                EnemyScript enemyScriptA = hitA.transform.GetComponent <EnemyScript>();
                EnemyScript enemyScriptB = hitB.transform.GetComponent <EnemyScript>();
                EnemyScript enemyScriptC = hitC.transform.GetComponent <EnemyScript>();

                if (enemyScriptA != null && enemyScriptB != null && enemyScriptC != null)
                {
                    if (enemyScriptA.knockedOut)
                    {
                        hit = hitA;
                    }
                    else if (enemyScriptB.knockedOut)
                    {
                        hit = hitB;
                    }
                    else if (enemyScriptC.knockedOut)
                    {
                        hit = hitC;
                    }
                    else if (hitA.distance <= hitB.distance && hitA.distance <= hitC.distance)
                    {
                        hit = hitA;
                    }
                    else if (hitB.distance <= hitA.distance && hitB.distance <= hitC.distance)
                    {
                        hit = hitB;
                    }
                    else if (hitC.distance <= hitA.distance && hitC.distance <= hitB.distance)
                    {
                        hit = hitC;
                    }
                }
                else if (enemyScriptA != null && enemyScriptB != null)
                {
                    if (hitA.distance <= hitB.distance)
                    {
                        hit = hitA;
                    }
                    else if (hitB.distance > hitA.distance)
                    {
                        hit = hitB;
                    }
                }
                else if (enemyScriptB != null && enemyScriptC != null)
                {
                    if (hitB.distance <= hitC.distance)
                    {
                        hit = hitB;
                    }
                    else if (hitC.distance > hitB.distance)
                    {
                        hit = hitC;
                    }
                }
                else if (enemyScriptA != null && enemyScriptC != null)
                {
                    if (hitA.distance <= hitC.distance)
                    {
                        hit = hitA;
                    }
                    else if (hitC.distance > hitA.distance)
                    {
                        hit = hitB;
                    }
                }
                else if (enemyScriptA != null)
                {
                    hit = hitA;
                }
                else if (enemyScriptB != null)
                {
                    hit = hitB;
                }
                else if (enemyScriptC != null)
                {
                    hit = hitC;
                }



                //Mostly working code

                /*
                 * if (hitA.transform.GetComponent<EnemyScript>().knockedOut)
                 *  hit = hitA;
                 * else if (hitB.transform.GetComponent<EnemyScript>().knockedOut)
                 *  hit = hitB;
                 * else if (hitC.transform.GetComponent<EnemyScript>().knockedOut)
                 *  hit = hitC;
                 * //else if(enemyScriptA && hitB.transform.GetComponent<EnemyScript>() && hitC.transform.GetComponent<EnemyScript>())
                 * else if(hitA.transform.GetComponent<EnemyScript>() && hitB.transform.GetComponent<EnemyScript>() && hitC.transform.GetComponent<EnemyScript>())
                 * {
                 *  if (hitA.distance <= hitB.distance && hitA.distance <= hitC.distance)
                 *      hit = hitA;
                 *  else if (hitB.distance <= hitA.distance && hitB.distance <= hitC.distance)
                 *      hit = hitB;
                 *  else if (hitC.distance <= hitA.distance && hitC.distance <= hitB.distance)
                 *      hit = hitC;
                 * }
                 * else if (hitA.transform.GetComponent<EnemyScript>() && hitB.transform.GetComponent<EnemyScript>())
                 * {
                 *  if (hitA.distance <= hitB.distance)
                 *      hit = hitA;
                 *  else if (hitB.distance > hitA.distance)
                 *      hit = hitB;
                 * }
                 * else if (hitB.transform.GetComponent<EnemyScript>() && hitC.transform.GetComponent<EnemyScript>())
                 * {
                 *  if (hitB.distance <= hitC.distance)
                 *      hit = hitB;
                 *  else if (hitC.distance > hitB.distance)
                 *      hit = hitC;
                 * }
                 * else if (hitA.transform.GetComponent<EnemyScript>() && hitC.transform.GetComponent<EnemyScript>())
                 * {
                 *  if (hitA.distance <= hitC.distance)
                 *      hit = hitA;
                 *  else if (hitC.distance > hitA.distance)
                 *      hit = hitB;
                 * }
                 * else if(hitA.transform.GetComponent<EnemyScript>())
                 *  hit = hitA;
                 * else if (hitB.transform.GetComponent<EnemyScript>())
                 *  hit = hitB;
                 * else if (hitC.transform.GetComponent<EnemyScript>())
                 *  hit = hitC;
                 */
                damage = (int)chargeAOEDamage;
                hit.transform.GetComponent <Rigidbody>().velocity = Vector3.zero;
                //chargeField.transform.localScale = area;
                nextCharge   = Time.time + chargeTimer;
                progress     = 5f - (nextCharge - Time.time);
                slider.value = progress;
                if (Time.time < nextCharge)
                {
                    ChargeImage.SetActive(false);
                }
                //Vector3 targetLocation = new Vector3(hit.point.x, 0, hit.point.z);
                targetHealth = hit.transform.GetComponent <Shootable>().currentHealth;
                health       = hit.transform.GetComponent <Shootable>();
                direction    = hit.point - transform.position;
                destination  = hit.point;
                dashed       = true;
                direction.Normalize();
                if (Vector3.Distance(destination, transform.position) > 4)
                {
                    StartCoroutine(StartCharge());
                }
                else
                {
                    StartCoroutine(EndCharge());
                }
                gameObject.GetComponent <Rigidbody>().AddForce((direction) * chargeSpeed);
                gameObject.GetComponent <PlayerMovement>().enabled   = false;
                gameObject.GetComponent <GunController>().enabled    = false;
                gameObject.GetComponent <AbsorbController>().enabled = false;
                gameObject.GetComponent <RepulsionField>().enabled   = false;
                target = hit.transform.gameObject;
                gameObject.GetComponent <Collider>().enabled = false;
                //hit.collider.GetComponent<EnemyController>().Death();
                gameObject.GetComponent <GunController>().ammo = gameObject.GetComponent <GunController>().maxAmmo;
                //Debug.Log("Just Reloaded, ammo = " + gameObject.GetComponent<GunController>().ammo);
                //StartCoroutine(ChargeTarget(hit));
                oopsTimer = Time.time + 2;
            }

            /* Working single ray cast
             * if (Physics.Raycast(transform.position, transform.forward, out hit, chargeRange) && hit.collider.tag == "Enemy")
             * {
             *  damage = (int)chargeAOEDamage;
             *  hit.collider.GetComponent<Rigidbody>().velocity = Vector3.zero;
             *  //chargeField.transform.localScale = area;
             *  nextCharge = Time.time + chargeTimer;
             *  progress = 5f - (nextCharge - Time.time);
             *  slider.value = progress;
             *  if (Time.time < nextCharge) { ChargeImage.SetActive(false); }
             *  //Vector3 targetLocation = new Vector3(hit.point.x, 0, hit.point.z);
             *  targetHealth = hit.collider.GetComponent<Shootable>().currentHealth;
             *  health = hit.collider.GetComponent<Shootable>();
             *  direction = hit.point - transform.position;
             *  destination = hit.point;
             *  dashed = true;
             *  direction.Normalize();
             *  if (Vector3.Distance(destination, transform.position) > 4)
             *      StartCoroutine(StartCharge());
             *  else
             *      StartCoroutine(EndCharge());
             *  gameObject.GetComponent<Rigidbody>().AddForce((direction) * chargeSpeed);
             *  gameObject.GetComponent<PlayerMovement>().enabled = false;
             *  gameObject.GetComponent<GunController>().enabled = false;
             *  gameObject.GetComponent<AbsorbController>().enabled = false;
             *  gameObject.GetComponent<RepulsionField>().enabled = false;
             *  target = hit.collider.gameObject;
             *  gameObject.GetComponent<Collider>().enabled = false;
             *  //hit.collider.GetComponent<EnemyController>().Death();
             *  gameObject.GetComponent<GunController>().ammo = gameObject.GetComponent<GunController>().maxAmmo;
             *  //Debug.Log("Just Reloaded, ammo = " + gameObject.GetComponent<GunController>().ammo);
             *  //StartCoroutine(ChargeTarget(hit));
             *  oopsTimer = Time.time + 2;
             * }*/
        }

        /*
         * if (transform.forward != direction && dashed)
         *  transform.forward = direction;
         */

        if (dashed && Time.time >= oopsTimer)
        {
            dashed = false;
            gameObject.GetComponent <PlayerMovement>().enabled = true;
        }

        if (Vector3.Distance(destination, transform.position) < 1 && dashed)
        {
            StartCoroutine(EndCharge());
            if (hit.collider.GetComponent <EnemyScript>().knockedOut)
            {
                damage = (int)(comboMultiplier * chargeAOEDamage);
            }
            health.Damage(targetHealth);
            target.GetComponent <EnemyScript>().Die();
            gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
            colliders = Physics.OverlapSphere(transform.position, chargeAOE);
            gameObject.GetComponent <Collider>().enabled = true;
            foreach (Collider col in colliders)
            {
                try
                {
                    col.GetComponent <Shootable>().currentHealth -= damage;
                }
                catch
                {
                }
            }
            dashed = false;
            gameObject.GetComponent <PlayerMovement>().enabled   = true;
            gameObject.GetComponent <GunController>().enabled    = true;
            gameObject.GetComponent <AbsorbController>().enabled = true;
            gameObject.GetComponent <RepulsionField>().enabled   = true;
        }
    }