Select item?

sebasfreelance

New member
Hi, I am using ULTIMATE CHARACTER CONTROLLER, I would like to activate a weapon by script, if my weapon is active I select an item (weapon) from the inventory of the ULTIMATE CHARACTER CONTROLLER,

can you help me?
I have looked in the help, and tried to use the script that comes from example, equip and use, but I have not got anything ...

I would like to do something like this, can you guide me?

using UnityEngine;

public class TPCInventory : MonoBehaviour
{
[Header("Weapons")]
[SerializeField]
private GameObject Revolver;

void Update()
{
// activa Knife del FPS Weapons
if (Revolver.activeInHierarchy == true)
{
equip a weapon from inventory?
}

// activa !Unarmed del FPS Weapons
else if (Revolver.activeInHierarchy == false)
{
deactivate the inventory weapon?
}
}
}


Thanks!
 
This page should help, under Equip:

 
I didn't get anything with the help, so I wrote here asking for help.

I used the scripts function but not me,

in the equip script
"Category index" I don't know what to put, like in the "Element set index"

I'm using your example scene, the character has all the items, but I don't know how to access them.

I don't know much about programming, could you tell me how to do it?

thanks
 
Hi

I have made it work well with my inventory, when you select a weapon from my inventory, it shows me and uses the weapon from your inventory, but I do not know why it does not work with the bow, it does not select it or it is not shown. I'm using

Code:
inventory.PickupItemType(m_Revolver, m_Count, -1, true, false);

the code I'm using to select weapons, As I said before, the pistol, the rifle, the shotgun work, but the bow does not.

Can you tell me how please?
thanks!!!

Code:
using UnityEngine;
using Opsive.UltimateCharacterController.Inventory;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using Opsive.UltimateCharacterController.Character;

public class TPCInventory : MonoBehaviour
{
    [Header("US Weapons")]
    [SerializeField] private GameObject Pistol;
    [SerializeField] private GameObject Rifle;
    [SerializeField] private GameObject Bow;
    [SerializeField] private GameObject Shotgun;

    [Header("Opsive Weapons")]
    [Tooltip("The character that should pickup the item.")]
    [SerializeField] protected GameObject m_Character;
    [Tooltip("The ItemType that the character should pickup.")]
    [SerializeField] protected ItemType opsivePistol;
    [SerializeField] protected ItemType opsiveRifle;
    [SerializeField] protected ItemType opsiveBow;
    [SerializeField] protected ItemType opsiveShotgun;
    [Tooltip("The number of ItemType that the character should pickup.")]
    [SerializeField] protected int m_Count = 1;

    void Update()
    {
        if (Pistol.activeInHierarchy == true)
        {
            EquipPistol();
        }
        else if (Rifle.activeInHierarchy == true)
        {
            EquipRifle();
        }
        else if (Bow.activeInHierarchy == true)
        {
            EquipBow();
        }
        else if (Shotgun.activeInHierarchy == true)
        {
            EquipShotgun();
        }
        else if (Revolver.activeInHierarchy == false && AssaultRifle.activeInHierarchy == false && WoodenBow.activeInHierarchy == false && Shotgun.activeInHierarchy == false)
        {
            UnEquip();
        }
    }

    void EquipPistol()
    {
        var inventory = m_Character.GetComponent<InventoryBase>();
        if (inventory == null)
        {
            return;
        }
        inventory.PickupItemType(opsivePistol, m_Count, -1, true, false);
    }

    void EquipRifle()
    {
        var inventory = m_Character.GetComponent<InventoryBase>();
        if (inventory == null)
        {
            return;
        }
        inventory.PickupItemType(opsiveRifle, m_Count, -1, true, false);
    }

    void EquipBow()
    {
        var inventory = m_Character.GetComponent<InventoryBase>();
        if (inventory == null)
        {
            return;
        }
        inventory.PickupItemType(opsiveBow, m_Count, -1, true, false);
    }

    void EquipShotgun()
    {
        var inventory = m_Character.GetComponent<InventoryBase>();
        if (inventory == null)
        {
            return;
        }
        inventory.PickupItemType(opsiveShotgun, m_Count, -1, true, false);
    }

    void UnEquip()
    {
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        if (characterLocomotion != null)
        {
            var equipUnequip = characterLocomotion.GetAbility<EquipUnequip>();
            if (equipUnequip != null)
            {
                equipUnequip.StartEquipUnequip(5);
            }
        }
    }
}
 
Glad you're making progress :)

If you're using the bow from the demo scene it has to be added a slightly different way because it is a runtime pickup. You'll first need to call Inventory.AddItem to actually add the runtime item, and then you can pick it up. ItemPickupBase.DoItemPickup has the code for this.

If you're just getting started with scripting though it'll be easier to create a new bow that is not a runtime pickup. That way you don't have to do anything extra.
 
Thank you very much, I will first try creating a new bow. see if I can get it to work

On the other hand, the support you are giving is appreciated, one of the best I have come across.
 
Top