Exemplo n.º 1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="dmgBouns">피해량 변동치(n배 : n)</param>
    /// <param name="speedBouns">탄속 변동치(n배 : n) min: 0.01</param>
    /// <param name="fireRate">연사 변동치(n배 : n) min: 0.1</param>
    /// <param name="costMagazine">탄 소모 변동치(n배 : n) min: 1</param>
    public void Shoot(float dmgBouns = 1f, float speedBouns = 1f, float fireRate = 1f, int costMagazine = 1)
    {
        if (dmgBouns < 0)
        {
            dmgBouns = 0;
        }
        if (speedBouns < 0.01f)
        {
            speedBouns = 0.01f;
        }
        if (fireRate < 0.1f)
        {
            fireRate = 0.1f;
        }
        if (costMagazine < 1)
        {
            costMagazine = 1;
        }

        if (Time.realtimeSinceStartup - fireTime < wpInfo.firerate / fireRate)
        {
            return;
        }
        if (wpInfo.curMagazine < 1)
        {
            return;
        }
        if (!weapons[useSlot])
        {
            return;
        }
        float      z  = transform.eulerAngles.z;
        GameObject go = op.Enable("Bullet1");
        Bullet     b  = go.GetComponent <Bullet>();

        go.layer = bulletLayer;
        b.Shoot(wpInfo.muzzle.position,
                transform.eulerAngles.z
                + Random.Range(-curMoa, curMoa),
                wpInfo.dmgNormal * dmgBouns,
                wpInfo.dmgCritical * dmgBouns,
                wpInfo.bulletSpeed * speedBouns,
                wpInfo.deadTime / speedBouns);
        fireTime            = Time.realtimeSinceStartup;
        wpInfo.curMagazine -= costMagazine;
        wpInfo.ShootSound();
        if (wpInfo.curMagazine <= 0)
        {
            wpInfo.curMagazine = 0;
            wpInfo.ClipSound();
            Reload();
        }

        if (wpInfo.moa <= wpInfo.spread)
        {
            curMoa = Vector2.Lerp(new Vector2(curMoa, 0), new Vector2(wpInfo.spread, 0), wpInfo.recoil).x;
            if (curMoa > wpInfo.spread)
            {
                curMoa = wpInfo.spread;
            }
        }
        else
        {
            curMoa = Vector2.Lerp(new Vector2(curMoa, 0), new Vector2(wpInfo.spread, 0), wpInfo.recoil).x;
            if (curMoa < wpInfo.spread)
            {
                curMoa = wpInfo.spread;
            }
        }
    }