Forum rules - please read before posting.

Can I use hotspots in Unity UI?

I have a Unity UI RawImage element in my scene, and I'd like to use AC hotspots instead of UI buttons to add some clickable areas on it. But when I add a hotspot as a child of the UI element in the hierarchy, it's not clickable.

I guess that makes sense, since the raycast happens on the AC camera, but is there a way around this?

Comments

  • You could potentially do it through script, since if you set your Hotspot detection method to Custom Script, you can use the following to make a Hotspot active:

    AC.KickStarter.playerInteraction.SetActiveHotspot (myHotspot);
    

    But to simply make something clickable, it's easier to just add a UI Button. You can have this run an ActionList asset file when clicked by adding a click event that invokes the asset's Interact function.

  • Thanks. I'm currently investigating my options. It's for an interactive comic book/CYOA-style game, do you know if anyone has done something similar with AC?
  • As in, those that present a list of choices to the player?

    Sounds very much like what AC offers in the form of Conversations - nothing springs to mind so far as needing things to be in a UI go.

    Bear in mind that you can always prefab your interactive objects and spawn them in front of the camera - that may be a workable alternative to using UI.

  • The idea is to have a vertically-scrollable UI element for each page (that's where unity UI comes in handy) and provide some options at the bottom, which can be ui buttons, since they'll just load a new scene.

    But in some cases, I want to have clickable areas inside the comic images (eg, a hidden objects mini-game, or to pick up an inventory item). That's where I'd like to use hotspots, to test the various AC's interaction methods which are not available with ui buttons. Those hotspots will be children of the scrollable UI element, and move along with it up and down.

    PS: I don't understand how the script you suggested works. Am I missing something or my initial description was not clear?

  • Do the pages take up the whole visible area of the screen? If so, it might be worth looking into having it be part of a more typical 2D scene and scroll the camera instead.

    What interaction mode specifically are you looking to make use of?

    Here's a sample script of what I was suggesting:

    using UnityEngine;
    using AC;
    
    public class SetHotspot : MonoBehaviour
    {
    
        public Hotspot hotspot;
    
        public void MakeActive ()
        {
            KickStarter.playerInteraction.SetActiveHotspot (hotspot);
        }
    
    }
    

    Set your Hotspot detection method to Custom Script, and then attach this script and Hotspot to a UI Button. Assign the Hotspot in this script's Inspector, and then wire up the UI Button's OnClick event to run this component's MakeActive function (the component on the same GameObject, not the script asset file).

    Doing so should cause the Hotspot to be made active upon clicking - so if you're using e.g. "Choose Hotspot Then Interaction" mode, it'll cause the Interaction menu for that Hotspot to show up.

  • Ah, I was hoping for a more automated approach, one that would actually raycast on the ui. But yes, that's the idea.

    In the meantime I did try the 2d camera with drag (on a 3d scene). It doesn't have the elastic feel of the scrollable ui, and setting the min/max limits is tricky, but it's promising. I'll investigate this approach a bit more.

    Thanks, Chris.
  • Raycasting a UI involves a different kind of ray, but it may be possible to detect Hotspot components and then call SetActiveHotspot automatically.

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.