Forum rules - please read before posting.

Equip Items

Hey there again.
I'm thinking in a way that I can equip items from inventory to the character.
So instead you use the item directly to the hotspot, you have to hold it with your hand to access that hotspot.
For example, I have a torch so I have to hold it in my hand, click on a fire and walk to a firepit to lit it.
So if i put the torch back to the backpack the fire goes out.

Comments

  • You can use a Global variable to keep track of what item's equipped, by creating a PopUp variable named e.g. "Equipped item" with values such as "Nothing", "Torch", etc.

    Though, it may be that the regular item-selection system is enough. You don't necessarily need to change the cursor icon to the selected item - you can have it just be displayed either in a menu, or by animating the player.

    For that, you can use a custom script that hooks into the OnInventorySelect / OnInventoryDeselect Actions to update the Player accordingly.

    One way to do that would be to create a Bool parameter on your Animator (named e.g. "EquippedTorch") and have a script set it to True whenever the Torch is equipped:

    using UnityEngine;
    using AC;
    
    public class EquipTorchAnimation : MonoBehaviour
    {
    
        public Animator _animator;
        public string torchBoolParameter = "EquippedTorch";
        public int torchItemID;
    
        private void OnEnable ()
        {
            EventManager.OnInventorySelect += OnInventorySelect;
            EventManager.OnInventoryDeselect += OnInventoryDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventorySelect -= OnInventorySelect;
            EventManager.OnInventoryDeselect -= OnInventoryDeselect;
        }
    
        private void OnInventorySelect (InvItem invItem)
        {
            _animator.SetBool (torchBoolParameter, invItem.id == torchItemID);
        }
    
        private void OnInventoryDeselect (InvItem invItem)
        {
            _animator.SetBool (torchBoolParameter, false);
        }
    
    }
    

    This is only speaking generally, however. If you'd like more detailed advice, share more details/screenshots on what you'd be looking to update visually.

  • edited December 2022

    Yeah yesterday I kept searching on the forum and tried some ideas I had, but I always prefer to ask it because you are the expert here and you solutioned a bunch of problems for me in these years. Sometimes I just come up with an absurdly complex idea and when I see your solution I feel dumb haha.

    I had some ideas yesterday when I was trying to test these mechanics, I came up with the idea to have the items you can equip in a different category, so normal items use the default mechcanics, like you click the item the mouse turns into the item and you use whatever you want.
    For the items you can equip by clicking on it, it will be highlighted in the inventory and it will have another UI with the selected item.
    However when I select the item it keeps in the mouse position.

    I did some tests pretty much closer that you did but for the UI. But I had some issues.
    For the items list, I couldn't find a way to hightlight it, I tried to remove from inventory but I hit in another problem.
    And how I keep track of the items list so I can show up the correct sprite in the UI to keep it simple and organized.

    Since I am not a good programmer I always have my final game with extremely complex codes and structures I can't understand haha.

  • edited December 2022

    Ok, I think I find a way:

    • Set Global variables to each Equip Item
    • When click on the item, remove it from inventory and set the GV to true
    • Check if global variables changed, check if the item is set to true
    • If so, turn on UI Images + animations, etc...
    • If clicked on the equipped item on UI, add item back to inventory
  • I just remove the idea of using inventory for it, I just make a interface that changes the global variables, I'm going to use the inventory just for the common items.

  • If you prefer, though the use of items should still be valid - though scripting may be best involved depending on your needs.

    You can show the "equipped item" in a separate InventoryBox element set to "Display Selected" - this will cause it to become visible automatically when an item is selected. This can also be limited to specific categories, to prevent it from showing when a "regular" item is selected.

    One thing to bear in mind, though, is that you wouldn't be able to use this approach if you wanted to use a regular item while something is equipped, since the equipped item would become de-selected. It'd still be possible to use items, but you'd have to manually set their "equipped" state upon clicking, rather than using the inventory-selection system.

    If you'd like to avoid scripting, however, then using a separate interface + global variables may indeed be the better approach.

  • Since I started to venture into creating games by myself with adventure creator, little by little I've been learning to make my own scripts and it's helped me a lot.
    Unfortunately I don't have all the time in the world to dedicate myself exclusively to creating these games, but whenever I have time I love to do new adventures.
    Ironically I own a game company however I only handle game design and art.

    Anyway thank you so much for the best support i have ever seen.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.