示例#1
0
 public void Hit()//Douchebags.
 {
     if (canHit)
     {
         RaycastHit hit;
         Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));//CrossHair
         if (Physics.Raycast(ray, out hit))
         {
             if (Vector3.Distance(this.gameObject.transform.position, hit.collider.gameObject.transform.position) < distance)
             {
                 Mover hitMover = hit.collider.gameObject.GetComponent <Mover>();
                 if (hitMover)
                 {
                     hitMover.ApplyDamage(damage);
                 }
                 if (hit.collider.gameObject.GetComponent <Rigidbody>() != null)
                 {
                     hit.collider.gameObject.GetComponent <Rigidbody>().AddForce((this.gameObject.transform.forward * damage), ForceMode.Impulse);
                 }
             }
         }
         canHit = false;
     }
     if (!hitTimer.IsStarted())
     {
         hitTimer.StartTimer(delay, 0, "HitIt");
     }
 }
示例#2
0
    public void doExplosion(float selfDamage)
    {
        //playExplosion();
        // playSound(explosionClip, AudioRolloffMode.Custom, false);
        // deathAudioClip = explosionClip;
        if (!isExploded)
        {
            /*
             * if (this.health < 20)
             * {
             *  selfDamage = 20;
             * }
             */
            GameObject newParticle = GameObject.Instantiate(explosionParticle, this.gameObject.transform.position, this.gameObject.transform.rotation) as GameObject;

            if (selfDamage < 1)
            {
                selfDamage = 20;
            }
            else
            {
                ApplyDamage(selfDamage);
            }

            isExploded = true;
            Collider[] colliders = Physics.OverlapSphere(this.gameObject.transform.position, explosionRad);
            for (int i = 0; i < colliders.Length; i++)
            {
                if (colliders[i].gameObject != this.gameObject)
                {
                    if (colliders[i].GetComponent <Rigidbody>())
                    {
                        colliders[i].gameObject.GetComponent <Rigidbody>().AddExplosionForce(explosionForce, this.gameObject.transform.position, explosionRad, 3.0f);
                    }
                    Mover mover = colliders[i].GetComponent <Mover>();
                    if (mover)
                    {
                        float distance = Vector3.Distance(this.gameObject.transform.position, colliders[i].gameObject.transform.position);
                        //mover.ApplyDamage((this.health / distance) + 10);
                        // mover.ApplyDamage((this.health / (distance > 0 ? distance : 1)) + 10);
                        mover.ApplyDamage((distance / explosionRad) * selfDamage);
                        // if(distance != 0)
                        // mover.ApplyDamage((distance > 0 ? selfDamage / distance : 0) + 10);
                    }
                }
            }
        }
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (!impacted)
        {
            if (targetObject == null)
            {
                Destroy(this.gameObject);
            }
            if (move)
            {
                this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, target, bulletSpeed * Time.deltaTime);
            }
            if (Vector3.Distance(this.gameObject.transform.position, target) < 1f)
            {
                if (targetObject == null)
                {
                    return;
                }
                if (isExplosive)
                {
                    Collider[] colliders = Physics.OverlapSphere(this.gameObject.transform.position, explosionRad);
                    for (int i = 0; i < colliders.Length; i++)
                    {
                        if (colliders[i].gameObject != this.gameObject)
                        {
                            if (colliders[i].GetComponent <Rigidbody>())
                            {
                                colliders[i].gameObject.GetComponent <Rigidbody>().AddExplosionForce(explosionForce, this.gameObject.transform.position, explosionRad, 3.0f);
                            }
                            Mover hurtMover = colliders[i].GetComponent <Mover>();
                            if (hurtMover)
                            {
                                float distance = Vector3.Distance(this.gameObject.transform.position, colliders[i].gameObject.transform.position);
                                hurtMover.ApplyDamage((distance > 0 ? bulletDmg / distance : 0) + 10);
                            }
                        }
                    }
                }

                Mover mover = targetObject.GetComponent <Mover>();
                if (mover != null)
                {
                    // if (!isExplosive)
                    //{
                    if (mover.GetType().ToString() != "Player")
                    {
                        mover.gameObject.transform.LookAt(gunHolder.gameObject.transform);
                    }

                    mover.ApplyDamage(bulletDmg);
                    //}
                }
                if (targetObject.GetComponent <Rigidbody>() != null)
                {
                    if (!isExplosive)
                    {
                        targetObject.GetComponent <Rigidbody>().AddForce((this.gameObject.transform.forward * bulletDmg), ForceMode.Impulse);
                    }
                }

                if (bulletParticle != null)
                {
                    GameObject newParticle = GameObject.Instantiate(bulletParticle, this.gameObject.transform.position, this.gameObject.transform.rotation) as GameObject;
                }
                //Destroy(this.gameObject);
                //Die();
                impacted = true;
                if (impactSound != null)
                {
                    AudioSource.PlayClipAtPoint(impactSound, this.gameObject.transform.position);
                }

                Destroy(this.gameObject.GetComponent <Renderer>());
                Destroy(this.gameObject.GetComponent <Collider>());
                Destroy(this.gameObject);
                Destroy(this);
            }
        }
    }