Пример #1
0
    /// <summary>
    /// Fire Sync in network player
    /// </summary>
    public void Fire(float m_spread, Vector3 pos, Quaternion rot)
    {
        if (IsGun != null)
        {
            //bullet info is set up in start function
            GameObject newBullet = Instantiate(m_bullet, pos, rot) as GameObject; // create a bullet
            // set the gun's info into an array to send to the bullet
            bl_BulletInitSettings t_info = new bl_BulletInitSettings();
            t_info.m_damage         = 0;
            t_info.m_ImpactForce    = 0;
            t_info.m_MaxPenetration = 0;
            t_info.m_maxspread      = IsGun.maxSpread;
            t_info.m_spread         = m_spread;
            t_info.m_speed          = IsGun.bulletSpeed;
            t_info.m_weaponname     = "";
            t_info.m_position       = this.transform.root.position;
            t_info.isNetwork        = true;

            newBullet.GetComponent <bl_Bullet>().SetUp(t_info);
            newBullet.GetComponent <bl_Bullet>().isTracer = true;
            GetComponent <AudioSource>().clip             = IsGun.FireSound;
            GetComponent <AudioSource>().spread           = Random.Range(1.0f, 1.5f);
            GetComponent <AudioSource>().Play();
        }
        if (m_muzzleFlash)
        {
            StartCoroutine(MuzzleFlash());
        }
    }
Пример #2
0
    /// Create and Fire 1 launcher projectile
    /// *** this is WIP ***
    IEnumerator FireOneProjectile()
    {
        Vector3 position = muzzlePoint.position; // position to spawn rocket / grenade is at the muzzle point of the gun

        bl_BulletInitSettings t_info = new bl_BulletInitSettings();

        t_info.m_damage         = damage;
        t_info.m_ImpactForce    = impactForce;
        t_info.m_MaxPenetration = maxPenetration;
        t_info.m_maxspread      = maxSpread;
        t_info.m_spread         = spread;
        t_info.m_speed          = bulletSpeed;
        t_info.m_weaponname     = GunName;
        t_info.m_position       = this.transform.root.position;
        t_info.m_weapinID       = GunID;
        t_info.isNetwork        = false;

        //Instantiate grenade
        GameObject newNoobTube = Instantiate(grenade, position, transform.parent.rotation) as GameObject;

        if (newNoobTube.GetComponent <Rigidbody>() != null)//if grenade have a rigitbody,then apply velocity
        {
            newNoobTube.GetComponent <Rigidbody>().angularVelocity = (UnityEngine.Random.onUnitSphere * 10f);
        }
        newNoobTube.GetComponent <bl_Grenade>().SetUp(t_info);// send the gun's info to the grenade

        if ((bulletsLeft == 0 && numberOfClips > 0))
        {
            StartCoroutine(reload());  // if out of bullets.... reload
            yield break;
        }
        grenadeFired = false;
    }
Пример #3
0
    /// Fire Sync in network player
    public void Fire(float m_spread,Vector3 pos,Quaternion rot)
    {
        if (IsGun != null)
        {
            //bullet info is set up in start function
            GameObject newBullet = Instantiate(m_bullet, pos, rot) as GameObject; // create a bullet
            // set the gun's info into an array to send to the bullet
            bl_BulletInitSettings t_info = new bl_BulletInitSettings();
            t_info.m_damage = 0;
            t_info.m_ImpactForce = 0;
            t_info.m_MaxPenetration = 0;
            t_info.m_maxspread = IsGun.maxSpread;
            t_info.m_spread = m_spread;
            t_info.m_speed = IsGun.bulletSpeed;
            t_info.m_weaponname = "";
            t_info.m_position = this.transform.root.position;
            t_info.isNetwork = true;

            newBullet.GetComponent<bl_Bullet>().SetUp(t_info);
            newBullet.GetComponent<bl_Bullet>().isTracer = true;
            GetComponent<AudioSource>().clip = IsGun.FireSound;
            GetComponent<AudioSource>().spread = Random.Range(1.0f, 1.5f);
            GetComponent<AudioSource>().Play();
        }
        if (m_muzzleFlash)
        {
            StartCoroutine(MuzzleFlash());
        }
    }
Пример #4
0
    /// <summary>
    /// if grenade
    /// </summary>
    /// <param name="s"></param>
    public void GrenadeFire(float s)
    {
        if (IsGun != null)
        {
            Vector3 position = FirePoint.position;                                                    // position to spawn bullet is at the muzzle point of the gun
            //bullet info is set up in start function
            GameObject newBullet = Instantiate(m_bullet, position, FirePoint.rotation) as GameObject; // create a bullet
            // set the gun's info into an array to send to the bullet
            bl_BulletInitSettings t_info = new bl_BulletInitSettings();
            t_info.m_damage         = 0;
            t_info.m_ImpactForce    = 0;
            t_info.m_MaxPenetration = 0;
            t_info.m_maxspread      = IsGun.maxSpread;
            t_info.m_spread         = s;
            t_info.m_speed          = IsGun.bulletSpeed;
            t_info.m_weaponname     = "";
            t_info.m_position       = this.transform.root.position;
            t_info.isNetwork        = true;

            newBullet.GetComponent <bl_Grenade>().SetUp(t_info);
            GetComponent <AudioSource>().clip   = IsGun.FireSound;
            GetComponent <AudioSource>().spread = Random.Range(1.0f, 1.5f);
            GetComponent <AudioSource>().Play();
        }
    }
Пример #5
0
    // tracer rounds for raycast bullets
    void FireOneTracer(bl_BulletInitSettings info)
    {
        Vector3    position  = muzzlePoint.position;
        GameObject newTracer = Instantiate(bullet, position, transform.parent.rotation) as GameObject; // create a bullet

        newTracer.SendMessageUpwards("SetUp", info);                                                   // send the gun's info to the bullet
        newTracer.GetComponent <bl_Bullet>().SetTracer();                                              // tell the bullet it is only a tracer
    }
Пример #6
0
    /// Create and fire a bullet
    IEnumerator FireOneShot()
    {
        Vector3 position = Camera.main.transform.position; // position to spawn bullet is at the muzzle point of the gun

        // set the gun's info into an array to send to the bullet
        bl_BulletInitSettings t_info = new bl_BulletInitSettings();

        t_info.m_damage         = damage;
        t_info.m_ImpactForce    = impactForce;
        t_info.m_MaxPenetration = maxPenetration;
        t_info.m_maxspread      = maxSpread;
        t_info.m_spread         = spread;
        t_info.m_speed          = bulletSpeed;
        t_info.m_weaponname     = GunName;
        t_info.m_position       = this.transform.root.position;
        t_info.m_weapinID       = this.GunID;
        t_info.isNetwork        = false;
        t_info.lifeTime         = range;

        //bullet info is set up in start function
        GameObject newBullet = Instantiate(bullet, position, transform.parent.rotation) as GameObject; // create a bullet

        newBullet.GetComponent <bl_Bullet>().SetUp(t_info);                                            // send the gun's info to the bullet

        if (!(typeOfGun == weaponType.Launcher))
        {
            if (shotsFired >= roundsPerTracer) // tracer round every so many rounds fired... is there a tracer this round fired?
            {
                if (newBullet.GetComponent <Renderer>() != null)
                {
                    newBullet.GetComponent <Renderer>().enabled = true; // turn on tracer effect
                }
                shotsFired = 0;                                         // reset tracer counter
            }
            else
            {
                if (newBullet.GetComponent <Renderer>() != null)
                {
                    newBullet.GetComponent <Renderer>().enabled = false; // turn off tracer effect
                }
            }
            GetComponent <AudioSource>().clip   = FireSound;
            GetComponent <AudioSource>().spread = Random.Range(1.0f, 1.5f);
            GetComponent <AudioSource>().Play();
        }

        if ((bulletsLeft == 0))
        {
            StartCoroutine(reload());  // if out of bullets.... reload
            yield break;
        }
    }
Пример #7
0
    /// <summary>
    /// Create and Fire a raycast
    /// and show an effect tracing of the bullet
    /// </summary>
    /// <returns></returns>
    IEnumerator FireOneRay()
    {
        int     hitCount       = 0;
        bool    tracerWasFired = false;
        Vector3 position       = muzzlePoint.position; // position to spawn bullet is at the muzzle point of the gun
        Vector3 direction      = muzzlePoint.TransformDirection(Random.Range(-maxSpread, maxSpread) * spread, Random.Range(-maxSpread, maxSpread) * spread, 1);
        //Vector3 dir = (weaponTarget.transform.position - position) + direction;

        // set the gun's info into an array to send to the bullet
        bl_BulletInitSettings t_info = new bl_BulletInitSettings();

        t_info.m_damage         = damage;
        t_info.m_ImpactForce    = impactForce;
        t_info.m_MaxPenetration = maxPenetration;
        t_info.m_maxspread      = maxSpread;
        t_info.m_spread         = spread;
        t_info.m_speed          = bulletSpeed;
        t_info.m_weaponname     = GunName;
        t_info.m_position       = this.transform.root.position;
        t_info.m_weapinID       = GunID;
        t_info.isNetwork        = false;

        if (shotsFired >= roundsPerTracer)
        {
            FireOneTracer(t_info);
            shotsFired     = 0;
            tracerWasFired = true;
        }

        RaycastHit[] hits = Physics.RaycastAll(position, direction, range);

        for (int i = 0; i < hits.Length; i++)
        {
            if (hitCount >= maxPenetration)
            {
                yield break;
            }

            RaycastHit hit = hits[i];
            //Debug.Log( "Bullet hit " + hit.collider.gameObject.name + " at " + hit.point.ToString() );

            // notify hit
            if (!tracerWasFired)
            {                  // tracers are set to show impact effects... we dont want to show more then 1 per bullet fired
                ShowHits(hit); // show impacts effects if no tracer was fired this round
            }

            // Debug.Log("if " + hitCount + " > " + maxHits + " then destroy bullet...");
            hitCount++;
        }
    }
Пример #8
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="s"></param>
    public void SetUp(bl_BulletInitSettings s)
    {
        damage             = s.m_damage;
        impactForce        = s.m_ImpactForce;
        maxInaccuracy      = s.m_maxspread;
        variableInaccuracy = s.m_speed;
        speed     = s.m_speed;
        ID        = s.m_weapinID;
        mName     = s.m_weaponname;
        isNetwork = s.isNetwork;
        //direction = transform.TransformDirection(0, 0, 1);
        direction = transform.TransformDirection(Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, 1);

        velocity = speed * transform.forward;

        GetComponent <Rigidbody>().velocity = velocity + direction;
        InvokeRepeating("Counter", 1, 1);
    }
Пример #9
0
    private Vector3 velocity = Vector3.zero; // bullet velocity

    #endregion Fields

    #region Methods

    public void SetUp(bl_BulletInitSettings s)
    {
        damage = s.m_damage;
        impactForce = s.m_ImpactForce;
        maxInaccuracy = s.m_maxspread;
        variableInaccuracy = s.m_speed;
        speed = s.m_speed;
        ID = s.m_weapinID;
        mName = s.m_weaponname;
        isNetwork = s.isNetwork;
        //direction = transform.TransformDirection(0, 0, 1);
        direction = transform.TransformDirection(Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, 1);

        velocity = speed * transform.forward;

        GetComponent<Rigidbody>().velocity = velocity + direction;
        InvokeRepeating("Counter", 1, 1);
    }
Пример #10
0
    public void SetUp(bl_BulletInitSettings info)   // information sent from gun to bullet to change bullet properties
    {
        damage             = info.m_damage;         // bullet damage
        impactForce        = info.m_ImpactForce;    // force applied to rigid bodies
        maxHits            = info.m_MaxPenetration; // max number of bullet impacts before bullet is destroyed
        maxInaccuracy      = info.m_maxspread;      // max inaccuracy of the bullet
        variableInaccuracy = info.m_spread;         // current inaccuracy... mostly for machine guns that lose accuracy over time
        speed         = info.m_speed;               // bullet speed
        DirectionFrom = info.m_position;
        GunName       = info.m_weaponname;
        OwnGunID      = info.m_weapinID;
        isNetwork     = info.isNetwork;
        // drection bullet is traveling
        direction = transform.TransformDirection(Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, 1);

        newPos   = transform.position;        // bullet's new position
        oldPos   = newPos;                    // bullet's old position
        velocity = speed * transform.forward; // bullet's velocity determined by direction and bullet speed

        // schedule for destruction if bullet never hits anything
        Destroy(gameObject, lifetime);
    }
Пример #11
0
 // tracer rounds for raycast bullets
 void FireOneTracer(bl_BulletInitSettings info)
 {
     Vector3 position = muzzlePoint.position;
     GameObject newTracer = Instantiate(bullet, position, transform.parent.rotation) as GameObject; // create a bullet
     newTracer.SendMessageUpwards("SetUp", info); // send the gun's info to the bullet
     newTracer.GetComponent<bl_Bullet>().SetTracer();  // tell the bullet it is only a tracer
 }
Пример #12
0
    /// Create and fire a bullet
    IEnumerator FireOneShot()
    {
        Vector3 position = Camera.main.transform.position; // position to spawn bullet is at the muzzle point of the gun

        // set the gun's info into an array to send to the bullet
        bl_BulletInitSettings t_info = new bl_BulletInitSettings();
        t_info.m_damage = damage;
        t_info.m_ImpactForce = impactForce;
        t_info.m_MaxPenetration = maxPenetration;
        t_info.m_maxspread = maxSpread;
        t_info.m_spread = spread;
        t_info.m_speed = bulletSpeed;
        t_info.m_weaponname = GunName;
        t_info.m_position = this.transform.root.position;
        t_info.m_weapinID = this.GunID;
        t_info.isNetwork = false;
        t_info.lifeTime = range;

        //bullet info is set up in start function
        GameObject newBullet = Instantiate(bullet, position, transform.parent.rotation) as GameObject; // create a bullet
        newBullet.GetComponent<bl_Bullet>().SetUp(t_info);// send the gun's info to the bullet

        if (!(typeOfGun == weaponType.Launcher))
        {
            if (shotsFired >= roundsPerTracer) // tracer round every so many rounds fired... is there a tracer this round fired?
            {
                if (newBullet.GetComponent<Renderer>() != null)
                    newBullet.GetComponent<Renderer>().enabled = true; // turn on tracer effect
                shotsFired = 0;                    // reset tracer counter
            }
            else
            {
                if (newBullet.GetComponent<Renderer>() != null)
                    newBullet.GetComponent<Renderer>().enabled = false; // turn off tracer effect
            }
            GetComponent<AudioSource>().clip = FireSound;
            GetComponent<AudioSource>().spread = Random.Range(1.0f, 1.5f);
            GetComponent<AudioSource>().Play();
        }

        if ((bulletsLeft == 0))
        {
            StartCoroutine(reload());  // if out of bullets.... reload
            yield break;
        }
    }
Пример #13
0
    /// Create and Fire a raycast
    /// and show an effect tracing of the bullet
    IEnumerator FireOneRay()
    {
        int hitCount = 0;
        bool tracerWasFired = false;
        Vector3 position = (typeOfGun == weaponType.Knife) ? Camera.main.transform.position : muzzlePoint.position; // position to spawn bullet is at the muzzle point of the gun
        Vector3 direction;
        if (typeOfGun != weaponType.Knife)
            direction = muzzlePoint.TransformDirection(Random.Range(-maxSpread, maxSpread) * spread, Random.Range(-maxSpread, maxSpread) * spread, 1);
        else
            direction = Camera.main.transform.TransformDirection(Vector3.forward);
        //Vector3 dir = (weaponTarget.transform.position - position) + direction;

        // set the gun's info into an array to send to the bullet
        bl_BulletInitSettings t_info = new bl_BulletInitSettings();
        t_info.m_damage = damage;
        t_info.m_ImpactForce = impactForce;
        t_info.m_MaxPenetration = maxPenetration;
        t_info.m_maxspread = maxSpread;
        t_info.m_spread = spread;
        t_info.m_speed = bulletSpeed;
        t_info.m_weaponname = GunName;
        t_info.m_position = this.transform.root.position;
        t_info.m_weapinID = GunID;
        t_info.isNetwork = false;

        if (shotsFired >= roundsPerTracer)
        {
            FireOneTracer(t_info);
            shotsFired = 0;
            tracerWasFired = true;
        }
        isFiring = false;
        RaycastHit[] hits = Physics.RaycastAll(position, direction, range);

        for (int i = 0; i < hits.Length; i++)
        {
            if (hitCount >= maxPenetration)
                yield break;

            RaycastHit hit = hits[i];
            Debug.Log("Bullet hit " + hit.collider.gameObject.name + " at " + hit.point.ToString());

            // notify hit
            if (!tracerWasFired)
            { // tracers are set to show impact effects... we dont want to show more then 1 per bullet fired
                bool b = (typeOfGun == weaponType.Knife) ? true : false;
                ShowHits(hit,b); // show impacts effects if no tracer was fired this round
            }

            // Debug.Log("if " + hitCount + " > " + maxHits + " then destroy bullet...");
            hitCount++;
        }
    }
Пример #14
0
    /// Create and Fire 1 launcher projectile
    /// *** this is WIP ***
    IEnumerator FireOneProjectile()
    {
        Vector3 position = muzzlePoint.position; // position to spawn rocket / grenade is at the muzzle point of the gun

        bl_BulletInitSettings t_info = new bl_BulletInitSettings();
        t_info.m_damage = damage;
        t_info.m_ImpactForce = impactForce;
        t_info.m_MaxPenetration = maxPenetration;
        t_info.m_maxspread = maxSpread;
        t_info.m_spread = spread;
        t_info.m_speed = bulletSpeed;
        t_info.m_weaponname = GunName;
        t_info.m_position = this.transform.root.position;
        t_info.m_weapinID = GunID;
        t_info.isNetwork = false;

        //Instantiate grenade
        GameObject newNoobTube = Instantiate(grenade, position, transform.parent.rotation) as GameObject;
        if (newNoobTube.GetComponent<Rigidbody>() != null)//if grenade have a rigitbody,then apply velocity
        {
            newNoobTube.GetComponent<Rigidbody>().angularVelocity = (UnityEngine.Random.onUnitSphere * 10f);
        }
        newNoobTube.GetComponent<bl_Grenade>().SetUp(t_info);// send the gun's info to the grenade

        if ((bulletsLeft == 0 && numberOfClips > 0))
        {
            StartCoroutine(reload());  // if out of bullets.... reload
            yield break;
        }
        grenadeFired = false;
    }
Пример #15
0
    // information sent from gun to bullet to change bullet properties
    public void SetUp(bl_BulletInitSettings info)
    {
        damage = info.m_damage;              // bullet damage
        impactForce = info.m_ImpactForce;         // force applied to rigid bodies
        maxHits = info.m_MaxPenetration;             // max number of bullet impacts before bullet is destroyed
        maxInaccuracy = info.m_maxspread;       // max inaccuracy of the bullet
        variableInaccuracy = info.m_spread;  // current inaccuracy... mostly for machine guns that lose accuracy over time
        speed = info.m_speed;               // bullet speed
        DirectionFrom = info.m_position;
        GunName = info.m_weaponname;
        OwnGunID = info.m_weapinID;
        isNetwork = info.isNetwork;
        lifetime = info.m_speed;
        // drection bullet is traveling
        direction = transform.TransformDirection(Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, Random.Range(-maxInaccuracy, maxInaccuracy) * variableInaccuracy, 1);

        newPos = transform.position;   // bullet's new position
        oldPos = newPos;               // bullet's old position
        velocity = speed * transform.forward; // bullet's velocity determined by direction and bullet speed

        // schedule for destruction if bullet never hits anything
        Destroy(gameObject, lifetime);
    }
Пример #16
0
    /// if grenade 
    public void GrenadeFire(float s)
    {
        if (IsGun != null)
        {
            Vector3 position = FirePoint.position; // position to spawn bullet is at the muzzle point of the gun
            //bullet info is set up in start function
            GameObject newBullet = Instantiate(m_bullet, position, FirePoint.rotation) as GameObject; // create a bullet
            // set the gun's info into an array to send to the bullet
            bl_BulletInitSettings t_info = new bl_BulletInitSettings();
            t_info.m_damage = 0;
            t_info.m_ImpactForce = 0;
            t_info.m_MaxPenetration = 0;
            t_info.m_maxspread = IsGun.maxSpread;
            t_info.m_spread = s;
            t_info.m_speed = IsGun.bulletSpeed;
            t_info.m_weaponname = "";
            t_info.m_position = this.transform.root.position;
            t_info.isNetwork = true;

            newBullet.GetComponent<bl_Grenade>().SetUp(t_info);
            GetComponent<AudioSource>().clip = IsGun.FireSound;
            GetComponent<AudioSource>().spread = Random.Range(1.0f, 1.5f);
            GetComponent<AudioSource>().Play();
        }
    }