示例#1
0
        private void OnEnable()
        {
            CameraEffects.Shake(ShakeForce, this.transform.position);
            Vector3 explosionPos = transform.position;

            Collider[] colliders = Physics.OverlapSphere(explosionPos, Radius);
            if (Sounds.Length > 0)
            {
                AudioSource.PlayClipAtPoint(Sounds [Random.Range(0, Sounds.Length)], transform.position);
            }
            foreach (Collider hit in colliders)
            {
                if (hit.GetComponent <Rigidbody>())
                {
                    hit.GetComponent <Rigidbody>().AddExplosionForce(Force, explosionPos, Radius, 3.0f);
                }
            }
        }
示例#2
0
        private void OnEnable()
        {
            CameraEffects.Shake(ShakeForce, this.transform.position);
            if (Sounds.Length > 0)
            {
                AudioSource.PlayClipAtPoint(Sounds [Random.Range(0, Sounds.Length)], transform.position);
            }
            if (Prefab)
            {
                for (int i = 0; i < Num; i++)
                {
                    Vector3 pos = new Vector3(Random.Range(-10, 10), Random.Range(-10, 20), Random.Range(-10, 10)) / 10f;

                    GameObject obj;
                    if (WeaponSystem.Pool != null)
                    {
                        obj = WeaponSystem.Pool.Instantiate(Prefab, transform.position + pos, Random.rotation, LifeTimeObject);
                    }
                    else
                    {
                        obj = (GameObject)Instantiate(Prefab, transform.position + pos, Random.rotation);
                        Destroy(obj, LifeTimeObject);
                    }

                    float scale = Scale;
                    if (RandomScale)
                    {
                        scale = Random.Range(1, Scale);
                    }

                    if (scale > 0)
                    {
                        obj.transform.localScale = new Vector3(scale, scale, scale);
                    }
                    if (obj.GetComponent <Rigidbody>())
                    {
                        Vector3 force = new Vector3(Random.Range(-Force.x, Force.x), Random.Range(-Force.y, Force.y), Random.Range(-Force.z, Force.z));
                        obj.GetComponent <Rigidbody>().AddForce(force);
                    }
                }
            }
        }
示例#3
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;
                }
            }
        }