Ejemplo n.º 1
0
    /// <summary>
    /// Fire Sync in network player
    /// </summary>
    public void Fire(float m_spread, Vector3 pos, Quaternion rot)
    {
        if (LocalGun != null)
        {
            //bullet info is set up in start function
            GameObject newBullet = Instantiate(Bullet, pos, rot) as GameObject; // create a bullet
            // set the gun's info into an array to send to the bullet
            bl_BulletSettings t_info = new bl_BulletSettings();
            t_info.Damage      = 0;
            t_info.ImpactForce = 0;
            t_info.MaxSpread   = LocalGun.maxSpread;
            t_info.Spread      = m_spread;
            t_info.Speed       = LocalGun.bulletSpeed;
            t_info.Position    = transform.root.position;
            t_info.isNetwork   = true;

            newBullet.GetComponent <bl_Bullet>().SetUp(t_info);
            newBullet.GetComponent <bl_Bullet>().isTracer = true;
            Source.clip   = LocalGun.FireSound;
            Source.spread = Random.Range(1.0f, 1.5f);
            Source.Play();
        }
        if (MuzzleFlash)
        {
            MuzzleFlash.Play();
        }
    }
Ejemplo n.º 2
0
    public void SetUp(bl_BulletSettings info)  // information sent from gun to bullet to change bullet properties
    {
        damage             = info.Damage;      // bullet damage
        impactForce        = info.ImpactForce; // force applied to rigid bodies
        maxInaccuracy      = info.MaxSpread;   // max inaccuracy of the bullet
        variableInaccuracy = info.Spread;      // current inaccuracy... mostly for machine guns that lose accuracy over time
        speed         = info.Speed;            // bullet speed
        DirectionFrom = info.Position;
        GunName       = info.WeaponName;
        OwnGunID      = info.WeaponID;
        isNetwork     = info.isNetwork;
        lifetime      = info.Speed;
        // direction 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
        if (Trail != null)
        {
            if (!bl_GameData.Instance.BulletTracer)
            {
                Destroy(Trail);
            }
        }
        // schedule for destruction if bullet never hits anything
        Destroy(gameObject, lifetime);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Create and Fire 1 launcher projectile
    /// </summary>
    /// <returns></returns>
    IEnumerator FireOneProjectile(Vector3 angular)
    {
        Vector3 position = muzzlePoint.position; // position to spawn rocket / grenade is at the muzzle point of the gun

        bl_BulletSettings t_info = new bl_BulletSettings();

        t_info.Damage      = Info.Damage;
        t_info.ImpactForce = impactForce;
        t_info.MaxSpread   = maxSpread;
        t_info.Spread      = spread;
        t_info.Speed       = bulletSpeed;
        t_info.WeaponName  = Info.Name;
        t_info.Position    = this.transform.root.position;
        t_info.WeaponID    = 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 rigidbody,then apply velocity
        {
            newNoobTube.GetComponent <Rigidbody>().angularVelocity = angular;
        }
        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;
    }
Ejemplo n.º 4
0
    // tracer rounds for raycast bullets
    void FireOneTracer(bl_BulletSettings info)
    {
        Vector3    position  = muzzlePoint.position;
        GameObject newTracer = Instantiate(bullet, position, transform.parent.rotation) as GameObject; // create a bullet

        newTracer.GetComponent <bl_Bullet>().SetUp(info);
        newTracer.GetComponent <bl_Bullet>().SetTracer();  // tell the bullet it is only a tracer
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Create and fire a bullet
    /// </summary>
    /// <returns></returns>
    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_BulletSettings t_info = new bl_BulletSettings();

        t_info.Damage      = Info.Damage;
        t_info.ImpactForce = impactForce;
        t_info.MaxSpread   = maxSpread;
        t_info.Spread      = spread;
        t_info.Speed       = bulletSpeed;
        t_info.WeaponName  = Info.Name;
        t_info.Position    = this.transform.root.position;
        t_info.WeaponID    = this.GunID;
        t_info.isNetwork   = false;
        t_info.LifeTime    = Info.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
        Crosshair.OnFire();

        if (!(Info.Type == GunType.Grenade))
        {
            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
                }
            }
            Source.clip   = FireSound;
            Source.spread = Random.Range(1.0f, 1.5f);
            Source.Play();
        }

        if ((bulletsLeft == 0))
        {
            StartCoroutine(reload());  // if out of bullets.... reload
            yield break;
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="s"></param>
    public void SetUp(bl_BulletSettings s)
    {
        damage             = s.Damage;
        impactForce        = s.ImpactForce;
        maxInaccuracy      = s.MaxSpread;
        variableInaccuracy = s.Spread;
        speed     = s.Speed;
        ID        = s.WeaponID;
        mName     = s.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);
    }
Ejemplo n.º 7
0
    /// <summary>
    /// if grenade
    /// </summary>
    /// <param name="s"></param>
    public void GrenadeFire(float s, Vector3 position, Quaternion rotation, Vector3 angular)
    {
        if (LocalGun != null)
        {
            //bullet info is set up in start function
            GameObject newBullet = Instantiate(Bullet, position, rotation) as GameObject; // create a bullet
            // set the gun's info into an array to send to the bullet
            bl_BulletSettings t_info = new bl_BulletSettings();
            t_info.MaxSpread = LocalGun.maxSpread;
            t_info.Spread    = s;
            t_info.Speed     = LocalGun.bulletSpeed;
            t_info.Position  = transform.root.position;
            t_info.isNetwork = true;

            if (newBullet.GetComponent <Rigidbody>() != null)//if grenade have a rigidbody,then apply velocity
            {
                newBullet.GetComponent <Rigidbody>().angularVelocity = angular;
            }
            newBullet.GetComponent <bl_Grenade>().SetUp(t_info);
            Source.clip   = LocalGun.FireSound;
            Source.spread = Random.Range(1.0f, 1.5f);
            Source.Play();
        }
    }