コード例 #1
0
    private void UpdateAmmo(Item i, Item lastItem, Image icon, TextMeshProUGUI name, TextMeshProUGUI clip, TextMeshProUGUI reserve)
    {
        if (i == null)
        {
            icon.sprite  = EmptyIcon;
            clip.text    = "";
            reserve.text = "";
            name.text    = "empty";
        }
        if (i != lastItem)
        {
            icon.sprite = i.InventoryIcon;
            lastItem    = i;
            name.text   = i.name;
        }
        EqpWeapon wep = i as EqpWeapon;

        if (wep == null)
        {
            clip.text    = "";
            reserve.text = "";
        }
        else
        {
            clip.text    = wep.CurrentAmmo + " / " + wep.ClipSize;
            reserve.text = Target.GetComponent <InventoryHolder>().GetItemCount(wep.AmmoType.GetComponent <Item>()).ToString();
        }
    }
コード例 #2
0
    protected void Reload(EqpWeapon wep, InventoryHolder ih)
    {
        int bulletsToReload = wep.ClipSize - wep.CurrentAmmo;
        int rem             = ih.RemoveItem(wep.AmmoType.GetComponent <Item>(), bulletsToReload);

        wep.CurrentAmmo += rem;
    }
コード例 #3
0
    protected override void OnAttack()
    {
        WeaponStats wp = m_weaponStats;

        base.OnAttack();
        EqpWeapon wep = null;

        if (SourceEqp != null)
        {
            wep = (EqpWeapon)SourceEqp;
            if (wep != null && wp.AmmoConsumedPerShot > wep.CurrentAmmo)
            {
                m_nextTimeCanFire = Time.timeSinceLevelLoad + wp.firedelay;
                return;
            }
        }
        m_charBase.GetComponent <Attackable>().DamageObj(wp.RecoilDamage);
        for (int i = 0; i < wp.shots; i++)
        {
            Vector3 rawTargetPoint = new Vector3(1f, 0f, 0f);
            rawTargetPoint = rawTargetPoint + new Vector3(wp.Offset.x, wp.Offset.y, 0f);
            float angle  = Mathf.Atan2(rawTargetPoint.y, rawTargetPoint.x);
            float spread = wp.spread * Mathf.Deg2Rad;
            float rand   = Random.Range(-spread, spread);

            angle += rand;
            Vector3 targetPoint = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0);
            //Debug.Log(rand + " : " + Mathf.Cos(angle) + " : " + Mathf.Sin(angle));
            createProjectile(wp.projectile, Vector2.zero, targetPoint, Random.Range(0f, m_weaponStats.randomDelay));
        }
        //if (wp.attackSound != null && wp.attackSound.Count > 0 && AudioManager != null)
        //    AudioManager.playSound(Weapon.attackSound[Random.Range(0, Weapon.attackSound.Count)]);
        if (wp.AmmoConsumedPerShot > 0 && wep != null)
        {
            wep.CurrentAmmo -= wp.AmmoConsumedPerShot;
        }
        m_nextTimeCanFire = Time.timeSinceLevelLoad + wp.firedelay;
    }