示例#1
0
    public void EquipWeapon(Weapon newWeapon)
    {
        Weapon oldWeapon = UnequipWeapon();

        if (onWeaponChanged != null)
        {
            onWeaponChanged.Invoke(newWeapon, oldWeapon);
        }

        //Spawn weapon
        currentWeapon = newWeapon;

        weaponInstance = Instantiate(currentWeapon.itemPrefab) as Transform;

        PlayerController _controller = FindObjectOfType <PlayerController>();

        if (_controller.isAiming)
        {
            _controller.OnWeaponActive();
        }
        else
        {
            _controller.OnWeaponInactive();
        }


        //Remove weapons pickup component
        GameObject.Destroy(weaponInstance.GetComponent <ItemPickup>());
        //Add weapon to an equipment slot
        weaponSlot.AddItem(currentWeapon);
    }
示例#2
0
    public void EquipWeapon(Weapon newWeapon)
    {
        Weapon oldWeapon = UnequipWeapon();

        if (onWeaponChanged != null)
        {
            onWeaponChanged.Invoke(newWeapon, oldWeapon);
        }

        //Spawn weapon
        currentWeapon = newWeapon;

        //TODO : pool instead
        weaponInstance = Instantiate(currentWeapon.itemPrefab) as Transform;
        weaponInstance.SetParent(weaponHandle);
        weaponInstance.localPosition    = Vector3.zero;
        weaponInstance.localScale       = Vector3.one;
        weaponInstance.gameObject.layer = LayerMask.NameToLayer("Player");
        //Remove weapons pickup component
        if (weaponInstance.GetComponent <InteractableItem>())
        {
            GameObject.Destroy(weaponInstance.GetComponent <InteractableItem>());
        }

        Inventory.Instance.RemoveItem(newWeapon);
        weaponSlot.AddItem(currentWeapon);
    }
示例#3
0
    void UpdateUI()
    {
        if (Equipment.instanse.item != null)
        {
            slot.AddItem(Equipment.instanse.item);
        }
        else
        {
            slot.ClearSlot();
        }

        Inventory.instanse.onItemChangedCallback.Invoke();
    }