Forum rules - please read before posting.

Highlight Hotspots when holding down Finger on Screen (Mobile)

edited January 2023 in Technical Q&A

Hi guys,

I know that there is a way to have the Hotspots always shown in a "soft" way, where they are always there but kind of transparent, as the default. But now, I would like that when holding the finger on the screen the HS Icons are changed to a stronger, brighter, bigger version that are easier to spot. Is there a way to implement this for mobile?

Thanks for any suggestions. If I have missed an already existing topic i'm sorry!

Robert

Comments

  • For the input side of the issue, this script on the AC wiki can be adapted to work with touch-screen input.

    Try this:

    using UnityEngine;
    using AC;
    
    public class HoldToFlash : MonoBehaviour
    {
    
        private bool isInGameplay;
    
        private void OnEnable () { EventManager.OnExitGameState += OnExitGameState; }
        private void OnDisable () { EventManager.OnExitGameState -= OnExitGameState; }
    
        private void Update ()
        {
            if (isInGameplay && Input.touchCount == 1)
            {
                if (Input.GetTouch (0).phase == TouchPhase.Ended)
                {
                    FlashHotspots (true);
                }
                else
                {
                    FlashHotspots ();
                }
            }
        }
    
        private void OnExitGameState (GameState gameState)
        {
            isInGameplay = (gameState != GameState.Normal);
            if (!isInGameplay)
            {
                FlashHotspots (true);
            }
        }
    
        private void CancelFlash ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspot.highlight)
                {
                    hotspot.highlight.CancelFlash ();
                }
            }
        }
    
        private void FlashHotspots ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspot.highlight && hotspot.IsOn () && hotspot.PlayerIsWithinBoundary () && hotspot != KickStarter.playerInteraction.GetActiveHotspot ())
                {
                    hotspot.highlight.flashHoldTime = 1000f;
                    hotspot.highlight.Flash ();
                }
            }
        }
    
    }
    

    This will cause the Hotspot "flash" effect to kick in while holding a finger down, but you'll need to assign a Highlight component to each Hotspot. What effect this has visually can be altered (through scripting if necessary), but see if this sorts out the input side of things first.

  • Oof, I'm still kind of hestitant to get into the actual scripting/coding stuff but I'll try to figure it out the basics in the next days and then work with your suggestions and get back if I still have any questions!

    Thank you very much!

  • Hi Chris,

    I managed to get the Hotspots to flash on a specific button press with the method described in the AC Wiki, defining "FlashHold" Input in the (old) Input Manager, however, if I change the script to your suggestion, nothing happens anymore :-(.

    I did change mouse input to simulate touch input, but it still does nothing.

    Do you think I could use the script from the AC Wiki, and then in the new Input Manager System define a "FlashHold" Input?
    Because I know that there I can easily define the touch inputs... I just don't know how to tell Unity/AC that it's supposed to be the "FlashHold" Input.

    Any suggestions?

  • The script on the wiki uses Input.GetButtonDown/Up - if you're on touch-screen, you don't need to use that and can instead use Input.touchCount:

    That's essentially what the modified script above does - but it'll only take effect when built to mobile. You can incorporate both - so that you can test in the Editor with FlashHold by replacing the above's Update function with:

    public string inputName = "FlashHold";
    private void Update ()
    {
        if (isInGameplay)
        {
            #if UNITY_EDITOR
            if (KickStarter.playerInput.InputGetButtonDown (inputName))
            {
                FlashHotspots ();
            }
            else if (KickStarter.playerInput.InputGetButtonUp (inputName))
            {
                FlashHotspots (true);
            }
            #else
            if (Input.touchCount == 1)
            {
            if (Input.GetTouch (0).phase == TouchPhase.Ended)
            {
                FlashHotspots (true);
            }
            else
            {
                FlashHotspots ();
            }
            }
            #endif
        }
    }
    

    This assumes you're using Unity's Input Manager system, however. By "new Input Manager System" are you referring to Input System?

    Try switching back to the old input manager - or at least allowing "Both" in Unity's Player settings - before incorporating Input System, to check that the script's behaviour is as you want first. Is it giving the proper intended behaviour otherwise?

  • edited March 2023

    Hmm so with the new script I can get the button that I defined in the input manager to flash the Hotspots but when I click with the mouse on the screen it still doesnt do anything. Am I doing something wrong? Does the mouseclick not simulate a touchpress? I activated the option to simulate touch in the debugger and also changed to build to IOS, still not working...

  • Is this an issue in builds, or only the Editor?

    In the Input Manager, you can set the input's Positive Button field to mouse 0 to have left-clicks trigger the input.

  • Yeah mouse 0 as left click trigger works… hmm must be something with the build then that it does not recognize the mouseclick as touch i assume.
  • The code above separates the inputs, so that only touches are recognised in the build. This version should allow both types at all times:

    public string inputName = "FlashHold";
    private void Update ()
    {
        if (isInGameplay)
        {
            if (KickStarter.playerInput.InputGetButtonDown (inputName))
            {
                FlashHotspots ();
            }
            else if (KickStarter.playerInput.InputGetButtonUp (inputName))
            {
                FlashHotspots (true);
            }
            else if (Input.touchCount == 1)
            {
                if (Input.GetTouch (0).phase == TouchPhase.Ended)
                {
                    FlashHotspots (true);
                }
                else
                {
                    FlashHotspots ();
                }
            }
        }
    }
    
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.