Forum rules - please read before posting.

Examine object when mouse over the Hotspot?

edited February 6 in Technical Q&A

Hi Chris:)

Is there any way to show some text when mouse over the Hotspot?
The idea is to show some kind of description text to the area when your mouse over. Let say you have a Sword, so when your mouse over it, you see not just a hotspot label but a short description of this Sword somewhere in the corner.

Same for the items in the inventory. Some kind of examine but in your screen. Any ideas?

Comments

  • For the hotspots,
    if you don't mind using custom script you could use OnMouseEnter() and OnMouseExit()

    You could call here an ActionList to avoid futher scripting that would show your menu and set the correct text to it.

  • You'll need some custom scripting - firstly to hook into events that trigger when the Menu turns on, and secondly to actually store the description text.

    Create a new Menu named "Description" and set its Appear type to On Hotspot. Give it a single Label element set to display a Global String Variable value, which we'll update with each descriptive text.

    Then attach this as a component to each Hotspot:

    using UnityEngine;
    using AC;
    
    [RequireComponent (typeof (Hotspot))]
    public class HotspotDescription : MonoBehaviour
    {
    
        public string description;
        private int stringVariableID = 0; // Set this as appropriate
    
        private void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
        private void OnDisable () { EventManager.OnMenuTurnOn -= OnMenuTurnOn; }
    
        private void OnMenuTurnOn (Menu menu, bool isInstant)
        {
            if (menu.title == "Description") 
            {
                if (KickStarter.playerInteraction.GetActiveHotspot () == GetComponent <Hotspot>())
                {
                    GlobalVariables.SetStringValue (stringVariableID, description);
                }
            }
        }
    
    }
    

    Replace the "0" in the script with the string variable's ID number, and write in the Description text in each Inspector.

    For Inventory items, create a new String Property in the Inventory Manager named Description, and type this in for each item.

    Then attach this to a single GameObject in your scene:

    using UnityEngine;
    using AC;
    
    public class InvItemDescription : MonoBehaviour
    {
    
        public int invPropertyID = 0; // Set this as appropriate
        private int stringVariableID = 0; // Set this as appropriate
    
        private void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
        private void OnDisable () { EventManager.OnMenuTurnOn -= OnMenuTurnOn; }
    
        private void OnMenuTurnOn (Menu menu, bool isInstant)
        {
            if (menu.title == "Description") 
            {
                if (KickStarter.runtimeInventory.hoverItem != null)
                {
                    string invItemDescription = KickStarter.runtimeInventory.hoverItem.GetProperty (invPropertyID).textVal;
                    GlobalVariables.SetStringValue (stringVariableID, invItemDescription);
                }
            }
        }
    
    }
    

    (Setting the "0" values to match your own)

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.
Do NOT follow this link or you will be banned from the site!