Forum rules - please read before posting.

FlashHotspots to flash small labels above each hotspot

edited December 2021 in Technical Q&A

Hi,

So I have my FlashHotspots script below, but I would like to edit it so that it instead flashes small Hotspot labels above each hotspot. The tricky part is, my in game usual Hotspot labels on hover are centered and large. Would I need to create a seperate Hotspot menu called SmallHotspotLabels set to above hotspot for the new script (which I will need your help with) to turn on when specific input is pressed?

Also, if I wanted my labels (Hotspot and SmallHotspotLabels menus) to animate a little, I assume they would have to be Unity UI prefab? See Script for just highlighting hotspots on input:

using UnityEngine;

if UNITY_EDITOR

using UnityEditor;

endif

namespace AC
{

[System.Serializable]
public class ActionFlashHotSpots : Action
{

// Declare variables here


public ActionFlashHotSpots ()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "FlashHotspot";
description = "Flashes Hotspots";
}


override public float Run ()
{
/*
* This function is called when the action is performed.
*
* The float to return is the time that the game
* should wait before moving on to the next action.
* Return 0f to make the action instantenous.
*
* For actions that take longer than one frame,
* you can return "defaultPauseTime" to make the game
* re-run this function a short time later. You can
* use the isRunning boolean to check if the action is
* being run for the first time, eg:
*/

         Hotspot[] hotspots = FindObjectsOfType (typeof (Hotspot)) as Hotspot[];
      foreach (Hotspot hotspot in hotspots)
      {
          if (hotspot.IsOn () && hotspot.PlayerIsWithinBoundary () && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot ())
          {
              hotspot.highlight.Flash ();
          }
      }
      
      if (!isRunning)
      {
          isRunning = true;
          return defaultPauseTime;
      }
      else
      {
          isRunning = false;
          return 0f;
      }
  }


  override public void Skip ()
  {
      /*
       * This function is called when the Action is skipped, as a
       * result of the player invoking the "EndCutscene" input.
       * 
       * It should perform the instructions of the Action instantly -
       * regardless of whether or not the Action itself has been run
       * normally yet.  If this method is left blank, then skipping
       * the Action will have no effect.  If this method is removed,
       * or if the Run() method call is left below, then skipping the
       * Action will cause it to run itself as normal.
       */

       Run ();
  }

  
  #if UNITY_EDITOR

  override public void ShowGUI ()
  {
      // Action-specific Inspector GUI code here
      
      AfterRunningOption ();
  }
  

  public override string SetLabel ()
  {
      // (Optional) Return a string used to describe the specific action's job.
      
      return string.Empty;
  }

  #endif
  

}

}

«1

Comments

  • A menu can only appear in one place at a time. For menu to appear in multiple places, it needs to be duplicated through script.

    A script that duplicates Hotspot menus so that they can appear when multiple Hotspots are highlighted can be found on the AC wiki:

    https://adventure-creator.fandom.com/wiki/Simultaneous_Hotspot_labels

  • ok, i have the script in my project but how do i incorporate it with the above script to flash only those hotspots? thanks!

  • The script can be attached to any of the Hotspots you want it to show for, but won't respond to Flash calls. Instead, you'll have to call HighlightOn and HighlightOff separately with a short gap in between:

    List<Hotspot> hotspotsList;
    public bool flashDuration = 0.5f;
    public override float Run ()
    {
        if (!isRunning)
        {
            hotspotsList = new List<Hotspot> ();
    
            Hotspot[] hotspots = FindObjectsOfType (typeof (Hotspot)) as Hotspot[];
            foreach (Hotspot hotspot in hotspots)
            {
                if (hotspot.IsOn () && hotspot.PlayerIsWithinBoundary () && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot ())
                {
                    hotspotsList.Add (hotspot);
                    hotspot.highlight.HighlightOn ();
                    isRunning = true;
                    return flashDuration;
                }
            }
        }
    
        foreach (Hotspot hotspot in hotspotsList)
        {
            hotspot.highlight.HighlightOff ();
        }
    
        isRunning = false;
        return 0f;
    }
    
  • edited December 2021

    So will all hotspots flash regardless of player vicinity? and I attach this to a gameobject in scene? And will flash the new hotspot menu created for the wiki script?

  • So will all hotspots flash regardless of player vicinity?

    The code above is an update to your custom Action's run function, which does account for player vicinity with:

    hotspot.PlayerIsWithinBoundary ()
    

    and I attach this to a gameobject in scene?

    Attach the wiki script to your Hotspots.

    And will flash the new hotspot menu created for the wiki script?

    It will show the Hotspot menu for Hotspots being highlighted.

  • edited December 2021

    Ok, so just checking as I am not always using player vicinity, but mouse over, so will this still account for that?

    So I add this code to the end of the wiki script?

    I have two hotspot menus, mouse over, and flash. I only want the flash hotspots to be visible when the player calls them with an input.

    Instead, you'll have to call HighlightOn and HighlightOff separately with a short gap in between:

    Can the player call this with an input?

    I also don't want the new hotspots to be called on mouse over in play, and only called via player input all together.

    Plus, currently it is just highlighting the new hotspot singularly when cursor over, instead of highlighting all the hotspots with the script on.

    See video here:

    https://www.dropbox.com/s/l6uirangesmqrzk/MultiHostposts.mov?dl=0

    I only want my main hotspot (big one at top) on mouse over, and smaller ones all to appear at the same time on player input. Thanks

  • edited December 2021

    Probably best to combine both scripts into a single Action - that way you can run it via an Active Input:

    using UnityEngine;
    using System.Collections.Generic;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionFlashHotSpots : Action
        {
    
            public float flashDuration = 0.5f;
            public string menuName = "Hotspot"; // The name of the Hotspot Menu to copy
            public string labelName = "HotspotLabel"; // The Label element of the Hotspot Menu
            private List<Menu> localMenus;
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "FlashHotspot"; }}
    
            public override float Run ()
            {
                if (!isRunning)
                {
                    localMenus = new List<Menu> ();
    
                    Hotspot[] hotspots = FindObjectsOfType (typeof (Hotspot)) as Hotspot[];
                    foreach (Hotspot hotspot in hotspots)
                    {
                        if (hotspot.IsOn () && hotspot.PlayerIsWithinBoundary () && hotspot.highlight && hotspot != KickStarter.playerInteraction.GetActiveHotspot ())
                        {
                            hotspot.Flash ();
                            ShowForHotspot (hotspot);
                        }
                    }
    
                    isRunning = true;
                    return flashDuration;
                }
    
                foreach (Menu menu in localMenus)
                {
                    menu.TurnOff ();
                    KickStarter.playerMenus.UnregisterCustomMenu (menu, false);
                }
    
                isRunning = false;
                return 0f;
            }
    
            private void ShowForHotspot (Hotspot hotspot)
            {
                Menu menuToCopy = PlayerMenus.GetMenuWithName (menuName);
                if (menuToCopy == null)
                {
                    ACDebug.LogWarning ("Cannot find menu with name '" + menuName + "'", this);
                    return;
                }
                Menu myMenu = ScriptableObject.CreateInstance<Menu> ();
    
                myMenu.CreateDuplicate (menuToCopy); // Copy from the default Menu
                myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily
                myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary
                myMenu.title += this.name;
                myMenu.SetHotspot (hotspot, null); // Link it to the Hotspot
    
                if (!string.IsNullOrEmpty (labelName))
                {
                    (myMenu.GetElementWithName (labelName) as MenuLabel).labelType = AC_LabelType.Normal;
                    (myMenu.GetElementWithName (labelName) as MenuLabel).label = hotspot.GetName (Options.GetLanguage ());
                }
    
                myMenu.TurnOn ();
    
                KickStarter.playerMenus.RegisterCustomMenu (myMenu, true);
                localMenus.Add (myMenu);
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                menuName = EditorGUILayout.TextField ("Menu name:", menuName);
                labelName = EditorGUILayout.TextField ("Label name:", labelName);
            }
    
            #endif
    
        }
    
    }
    
  • edited December 2021

    Getting this error, and script not appearing in the actions manager in Custom list:

    The script '/Users/jlightfoot001/Dropbox/Sleepytime Village URP/Assets/Sleepytime Village/Scripts/CustomActions/ActionFlashHotspots.cs' must derive from AC's Action class in order to be available as an Action.

    and this:

    The script '/Users/jlightfoot001/Dropbox/Sleepytime Village URP/Assets/Sleepytime Village/Scripts/CustomActions/ActionFlashHotspots.cs' must derive from AC's Action class in order to be available as an Action.

  • The filename must match the class name, ActionFlashHotSpots, and it's case-sensitive.

  • ok changed that, i get this error:

    Assets/Sleepytime Village/Scripts/CustomActions/ActionFlashHotSpots.cs(39,24): error CS0029: Cannot implicitly convert type 'bool' to 'float'

  • Typo. Replace:

    public bool flashDuration = 0.5f;
    

    with:

    public float flashDuration = 0.5f;
    
  • ok awesome thanks! And how do i set this up for input so that when the player presses F for example, all the new smaller hotspots flash?

  • As currently the smaller hotspots still appear when the cursor is over them (I want them kicked off until F is pressed and then they all flash their label in scene )
  • And how do i set this up for input so that when the player presses F for example, all the new smaller hotspots flash?

    Use an Active Input to run an ActionList with the above Action.

    currently the smaller hotspots still appear when the cursor is over them

    You can lock the original Hotspot menu - it won't interfere with the duplicates that the Action creates.

  • edited December 2021

    ok, I have set it up like so, but on pressing F, nothing happens? Plus, my new flashhostpost only menu is locked off, yet is still active on hover in play? It shows along with my normal hotspots (all in screenshots)

    https://www.dropbox.com/sh/0zkr6vzeawd7esm/AAAmUEH16SvHGvJhgEq0rFnfa?dl=0

  • "Input Button" refers to the listing in Unity's Input Manager - not the key itself.

  • works perfectly! thanks!!

  • edited December 2021

    final q's:

    1. Can i have them stay visible until key is depressed?

    2. How would I get the label background texture to auto resize to length of label string? I assume this is a UI prefab and not AC menu?

    3. When I press F to flash the hotspots, it is flashing hidden hotspots too, any way to sort this?

    4. Also, can hotspots automatically stay out of other hotspots way? see screenshot:

    https://www.dropbox.com/sh/0zkr6vzeawd7esm/AAAmUEH16SvHGvJhgEq0rFnfa?dl=0

  • Can i have them stay visible until key is depressed?

    Not through flashing. Flashing refers to to the highlight effect turning on and off in one go - you would need a rewrite to have the behaviour be different.

    How would I get the label background texture to auto resize to length of label string? I assume this is a UI prefab and not AC menu?

    Using Unity UI, it's a case of attaching the correct UI components, e.g. Content Size Fitter. This isn't related to AC, however.

    When I press F to flash the hotspots, it is flashing hidden hotspots too, any way to sort this?

    Hidden in what way?

    Also, can hotspots automatically stay out of other hotspots way? see screenshot:

    A Hotspot menu with a "Position" property of "On Hotspot" will show over that Hotspot's centre. You can override this on a per-Hotspot basis though by creating a new empty GameObject to represent the intended position, and assigning it as the Hotspot's Centre-point (override) Inspector field.

  • Hidden in what way?

    They are disabled but still showing when flashing

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.