Forum rules - please read before posting.

Interactable hotspots within a text-adventure style game

Hello fellow adventurers,

I am putting together some basic systems for a hybrid text-adventure style game. There will be the main display of text where the story unfolds, and then the AC inventory system at the bottom.

Essentially, I want the player to be able to interact with certain words, as if they were hotspots. IE, drag a key item from the inventory onto the word 'door' to unlock it.

I am stuck trying to get an interactable hotspot to work within a UI element. I followed this thread

https://adventurecreator.org/forum/discussion/10636/can-i-use-hotspots-in-unity-ui

but that does not let me simply drag an item over the button to interact. The button must be clicked to activate the hotspot, and then, for some reason, the hotspot is registered anywhere on the screen - a click anywhere on screen will interact with the hotspot, rather than only over the specific hotspot element. And then the hotspot cannot be turned off.

Is there a better way to do this? I tried using 3D TMP Text element, which does not use the UI so I could simply put a hotspot over the word I wanted, but I cannot figure out how make a scrolling text (adding a scroll rect) element outside of the UI canvas.

Any ideas? Thank you so much!

Comments

  • Welcome to the community, @ryanfaelen.

    Essentially, I want the player to be able to interact with certain words, as if they were hotspots. IE, drag a key item from the inventory onto the word 'door' to unlock it.

    As a fan of text adventures, that's a great idea!

    I'd expect the cleanest way to handle this would be to leverage TMPro's link tag to mark your interactive text portions with a unique ID.

    This is because TMPro has a helper function - FindIntersectingLink - to determine which link the mouse is currently over. A custom script could feasibly compare this link's ID with one you specify, and run an ActionList if you then de-select a given item while over it.

    This may need tweaking, but it's probably something along these lines:

    using UnityEngine;
    using AC;
    using TMPro;
    
    public class ItemLink : MonoBehaviour
    {
    
        public TMP_Text textBox;
        public string linkID;
        public ActionList actionList;
        public int itemID;
        private bool isOverLink;
    
        void OnEnable () { EventManager.OnInventoryDeselect += OnInventoryDeselect; }
        void OnDisable () { EventManager.OnInventoryDeselect -= OnInventoryDeselect; }
    
        void Update ()
        {
            int linkIndex = TMP_TextUtilities.FindIntersectingLink (textBox, Input.mousePosition, KickStarter.CameraMain);
            if (linkIndex != -1)
            {
                TMP_LinkInfo linkInfo = textBox.textInfo.linkInfo[linkIndex];
                if (linkInfo.GetLinkID () == linkID)
                {
                    isOverLink = true;
                    return;
                }
            }
            isOverLink = false;
        }
    
        void OnInventoryDeselect (InvItem invItem)
        {
            if (isOverLink && invItem.id == itemID)
            {
                actionList.Interact ();
            }
        }
    
    }
    
  • Thanks, Chris. Would this change if the user has a touch screen device?
  • I'd say let's check that it works on desktop first, but otherwise it should just be a case of replacing:

    Input.mousePosition
    

    with:

    KickStarter.playerInput.GetMousePosition ()
    

    That will have it rely on AC's cursor position, so it ought then to be cross-platform.

  • Great I will given it a try and report back.
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.