Forum rules - please read before posting.

Left-click to Use, Hover to Examine

Hi everyone,

Hope everyone is doing well :)

From the title, might it be possible to still have the left-click fire "use" interactions while having cursor-hovers fire "examine" interactions (instead of right-clicking) ?

I'm currently using this script from another forum thread to deal with a "description" menu that pops up when hovering over a hotspot, but I'm wondering if it is possible to do this natively with pure AC.

Any help is appreciated, thank you! :smiley:

«1

Comments

  • The use of the OnHotspotSelect custom event is the best way to handle this.

  • Thank you so much! Based on my understanding, would this mean I still require a script for this?

    I was wondering because I am hoping to also change the "description" based on some boolean variables through the game.

  • You would need a script, yes, but you can still have that script run an ActionList to handle the logic that runs.

    Can you elaborate more on exactly what you're looking to do? I'm not clear if you want to adapt the description-box script on the linked thread, or just run a separate ActionList when hovering over a given Hotspot.

  • Yeah for sure!

    So I guess what I'm aiming to do is have a description pop up when hovering over a hotspot. I was wondering if it would be possible to do this without an external C# script -- so something I was hoping to do was repurpose the "examine" interactions from needing to be "right-clicked" and instead just be hoverable.

    The other component of this is that the description of these hotspots may change after events / variable changes, so I am wondering if this would still require an external script.

    Currently, this is what I have here (sorry for some reason I am unable to upload a video directly).

    I'll paste the link here as well in case: https://drive.google.com/drive/u/1/folders/1H8NOeCzpyE0FhLpB7i8zOZ73WyqXwmnY

    When I am hovering over here for example, the description box below pops up.

    This is how it is showing as a component in Unity:
    https://drive.google.com/file/d/1vpwQt70cuIavXmTap2Uy1V07n7X_jhPm/view?usp=share_link

    And this is the current C# script for "Hotspot Description" that I have:

    using UnityEngine;
    using AC;
    
    [RequireComponent(typeof(Hotspot))]
    public class HotspotDescription : MonoBehaviour
    {
        // variable that determines if hovered-description is different for each playable character
        public bool isDifferentForEachCharacter = false;
    
        // description line
        [TextArea] //added for line breaks
        public string description;
        private int stringVariableID = 2; // 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);
                }
            }
        }
    
        private void Update()
        {
            if (KickStarter.playerInteraction.GetActiveHotspot() == GetComponent<Hotspot>())
            {
                GlobalVariables.SetStringValue(stringVariableID, description);
            }
        }
    
    }
    
  • Yes, you'd need a script for that.

    It looks like what you have is already working for what you need, but if you wanted a more general-purpose script that simply runs a Hotspot's examine interaction upon hovering over it, you can use this instead:

    using UnityEngine;
    using AC;
    
    public class AutoExamineHotspot : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnHotspotSelect += OnHotspotSelect; }
        private void OnDisable () { EventManager.OnHotspotSelect -= OnHotspotSelect; }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            if (hotspot.gameObject == gameObject)
            {
                hotspot.RunExamineInteraction ();
            }
        }
    
    }
    
  • Perfect, thank you so much! :)

  • @ChrisIceBox Just refreshing this thread a bit -- I noticed this menu also gets activated for inventory items.

    However, I just want it to be for hotspots; how can I change this?

    Thank you!

  • The scripts don't deal with when the Menu is displayed - that's still determined by the Menu's Appear type property.

    Is it set to On Hotspot? If so, it will react to Inventory items - or any Menu that has a "Hotspot label".

    To prevent it from showing when over the Inventory, just re-arrange the Inventory menu in the Menu Manager so that it's underneath the Hotspot menu. This is the order in which Menus are processed - so having Hotspot be processed first will cause it to be updated before Inventory.

  • Ah gotcha! Thank you so much!

    Do you know where I can add the AutoExamineHotspot script you mentioned above so that it will run the examine interactions automatically?

  • Ah nvm! I went back to the first thread I linked in the original post -- so would I need to connect it to every hotspot?

    I tried it out for one hotspot and it worked! Just wondering if there was a catch-all solution or if I may need to add it to each hotspot.

    Thanks!

  • Sorry, there's a few scripts now in all these threads - which one(s) specifically are you dealing with now?

  • edited January 3

    Ah this is the AutoExamineHotspot script that was pasted above!

    Also it seems to be interfering with my inventory actions -- when I paste this script on the corresponding hotspot, the inventory item cursor becomes the use interaction cursor for some reason instead of remaining as the selected inventory item.

    Do you know how I could fix this? Thanks!

  • edited January 3

    So in other words -- it seems that the examine interaction is overriding the inventory interaction from what I'm gathering?

  • I made a superbly complicated solution for this that works when hovering on hotspots and inventory items. I am not sure if the code in my blog post is quite up to date, but it might give you some hints on how I did the same.https://echoesofsomewhere.com/2023/06/12/ui-systems/

  • As an accessibility option & localisation helps I already set it up this week so that it uses text from the speech system and by keeping the cursor on the hotspot for 1.5 s the examine text is spoken. (toggle in options) I am sure my code is horrible and possibly the worst way to do it, but it works :D

  • Here's the script, adapted to work for all Hotspots in the scene - and only when no Inventory item is currently selected:

    using UnityEngine;
    using AC;
    
    public class AutoExamineHotspot : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnHotspotSelect += OnHotspotSelect; }
        private void OnDisable () { EventManager.OnHotspotSelect -= OnHotspotSelect; }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            if (KickStarter.runtimeInventory.SelectedItem == null)
            {
                hotspot.RunExamineInteraction ();
            }
        }
    
    }
    
  • @jussik @ChrisIceBox omg thank you both so much, really appreciate it!! :)
    @jussik Definitely feel you on the hacky solutions haha -- ik it's probably not a good thing for me to say, but if it works, it works!! :D

  • Yep I have a feeling I may rewrite my solution at some point in time to make it prettier :D

  • I rewrote my solution "the correct way" I will update the blog later. fyi

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.