Exemple #1
0
        void chainDamage()
        {
            int count = 0;

            for (int t = 0; t < TargetTag.Length; t++)
            {
                TargetCollector collector = WeaponSystem.Finder.FindTargetTag(TargetTag [t]);
                if (collector != null)
                {
                    GameObject[] objs     = collector.Targets;
                    float        distance = Distance;


                    for (int i = 0; i < objs.Length; i++)
                    {
                        if (objs [i] != null)
                        {
                            Vector3 dir       = (objs [i].transform.position - this.transform.position).normalized;
                            float   direction = Vector3.Dot(dir, this.transform.forward);
                            float   dis       = Vector3.Distance(objs [i].transform.position, this.transform.position);
                            if (dis < distance)
                            {
                                if (direction >= Direction)
                                {
                                    if (ChainObject)
                                    {
                                        if (count <= NumberChain)
                                        {
                                            GameObject chain;
                                            Quaternion targetlook = Quaternion.LookRotation(objs [i].transform.position - this.transform.position);
                                            if (WeaponSystem.Pool != null)
                                            {
                                                chain = WeaponSystem.Pool.Instantiate(ChainObject, this.transform.position, targetlook);
                                            }
                                            else
                                            {
                                                chain = (GameObject)GameObject.Instantiate(ChainObject, this.transform.position, targetlook);
                                            }

                                            DamageBase dmg = chain.GetComponent <DamageBase> ();
                                            if (dmg)
                                            {
                                                dmg.TargetTag = TargetTag;
                                            }
                                            count += 1;
                                        }
                                    }
                                }
                                distance = dis;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void Shoot()
        {
            if (InfinityAmmo)
            {
                Ammo = 1;
            }
            if (Ammo > 0)
            {
                if (Time.time > nextFireTime + FireRate)
                {
                    CameraEffects.Shake(ShakeForce, this.transform.position);
                    nextFireTime = Time.time;
                    torqueTemp   = TorqueSpeedAxis;
                    Ammo        -= 1;
                    Vector3    missileposition = this.transform.position;
                    Quaternion missilerotate   = this.transform.rotation;
                    if (MissileOuter.Length > 0)
                    {
                        missilerotate   = MissileOuter [currentOuter].rotation;
                        missileposition = MissileOuter [currentOuter].position;
                    }

                    if (MissileOuter.Length > 0)
                    {
                        currentOuter += 1;
                        if (currentOuter >= MissileOuter.Length)
                        {
                            currentOuter = 0;
                        }
                    }

                    if (Muzzle)
                    {
                        GameObject muzzle;
                        if (WeaponSystem.Pool != null)
                        {
                            muzzle = WeaponSystem.Pool.Instantiate(Muzzle, missileposition, missilerotate, MuzzleLifeTime);
                        }
                        else
                        {
                            muzzle = (GameObject)GameObject.Instantiate(Muzzle, missileposition, missilerotate);
                            GameObject.Destroy(muzzle, MuzzleLifeTime);
                        }

                        muzzle.transform.parent = this.transform;
                        if (MissileOuter.Length > 0)
                        {
                            muzzle.transform.parent = MissileOuter [currentOuter].transform;
                        }
                    }

                    for (int i = 0; i < NumBullet; i++)
                    {
                        if (Missile)
                        {
                            Vector3 spread    = new Vector3(Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), Random.Range(-Spread, Spread)) / 100;
                            Vector3 direction = this.transform.forward + spread;
                            missilerotate = Quaternion.LookRotation(direction);

                            GameObject bullet;
                            if (WeaponSystem.Pool != null)
                            {
                                bullet = WeaponSystem.Pool.Instantiate(Missile, missileposition, missilerotate);
                            }
                            else
                            {
                                bullet = (GameObject)GameObject.Instantiate(Missile, missileposition, missilerotate);
                            }
                            if (bullet)
                            {
                                DamageBase damangeBase = bullet.GetComponent <DamageBase> ();
                                if (damangeBase)
                                {
                                    damangeBase.Owner     = Owner;
                                    damangeBase.TargetTag = TargetTag;
                                    damangeBase.IgnoreTag = IgnoreTag;
                                    damangeBase.IgnoreSelf(this.gameObject);
                                }
                                WeaponBase weaponBase = bullet.GetComponent <WeaponBase> ();
                                if (weaponBase)
                                {
                                    weaponBase.Owner     = Owner;
                                    weaponBase.Target    = target;
                                    weaponBase.TargetTag = TargetTag;
                                    weaponBase.IgnoreTag = IgnoreTag;
                                }
                                if (RigidbodyProjectile)
                                {
                                    if (bullet.GetComponent <Rigidbody> ())
                                    {
                                        if (Owner != null && Owner.GetComponent <Rigidbody> ())
                                        {
                                            bullet.GetComponent <Rigidbody> ().velocity = Owner.GetComponent <Rigidbody> ().velocity;
                                        }
                                        bullet.GetComponent <Rigidbody> ().AddForce(direction * ForceShoot);
                                    }
                                }
                            }
                        }
                    }
                    if (Shell)
                    {
                        Transform shelloutpos = this.transform;
                        if (ShellOuter.Length > 0)
                        {
                            shelloutpos = ShellOuter [currentOuter];
                        }
                        GameObject shell;
                        if (WeaponSystem.Pool != null)
                        {
                            shell = WeaponSystem.Pool.Instantiate(Shell, shelloutpos.position, Random.rotation, ShellLifeTime);
                        }
                        else
                        {
                            shell = (GameObject)Instantiate(Shell, shelloutpos.position, Random.rotation);
                            GameObject.Destroy(shell.gameObject, ShellLifeTime);
                        }

                        if (shell.GetComponent <Rigidbody> ())
                        {
                            shell.GetComponent <Rigidbody> ().AddForce(shelloutpos.forward * ShellOutForce);
                        }
                    }

                    if (SoundGun.Length > 0)
                    {
                        if (audioSource)
                        {
                            audioSource.PlayOneShot(SoundGun [Random.Range(0, SoundGun.Length)]);
                        }
                    }

                    nextFireTime += FireRate;
                }
            }
        }
Exemple #3
0
        void ShootRay()
        {
            if (GetComponent <Collider>())
            {
                Physics.IgnoreCollision(GetComponent <Collider>(), Owner.GetComponent <Collider>());
                if (Owner.transform.root)
                {
                    foreach (Collider col in Owner.transform.root.GetComponentsInChildren <Collider>())
                    {
                        Physics.IgnoreCollision(GetComponent <Collider>(), col);
                    }
                }
            }

            RaycastHit hit;
            GameObject explosion = null;

            if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, Range))
            {
                AimPoint = hit.point;
                if (Explosion != null)
                {
                    if (WeaponSystem.Pool != null)
                    {
                        explosion = WeaponSystem.Pool.Instantiate(Explosion, AimPoint, this.transform.rotation);
                    }
                    else
                    {
                        explosion = (GameObject)GameObject.Instantiate(Explosion, AimPoint, this.transform.rotation);
                    }
                }
                hit.collider.gameObject.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                AimPoint = this.transform.position + this.transform.forward * Range;
                if (Explosion != null)
                {
                    if (WeaponSystem.Pool != null)
                    {
                        explosion = WeaponSystem.Pool.Instantiate(Explosion, AimPoint, this.transform.rotation);
                    }
                    else
                    {
                        explosion = (GameObject)GameObject.Instantiate(Explosion, AimPoint, this.transform.rotation);
                    }
                }
            }
            if (explosion)
            {
                explosion.transform.forward = this.transform.forward;
                DamageBase dmg = explosion.GetComponent <DamageBase> ();
                if (dmg)
                {
                    dmg.TargetTag = TargetTag;
                }
            }
            if (Trail)
            {
                Trail.SetPosition(0, this.transform.position);
                Trail.SetPosition(1, AimPoint);
            }

            if (WeaponSystem.Pool == null)
            {
                Destroy(this.gameObject, LifeTime);
            }
        }