Forum rules - please read before posting.

Hotspot Use Button on GUI

edited April 2018 in Technical Q&A
Hi. I'm making first-person mobile game with virtual joystick which i asked before.

The hotspot setting that I want is like Granny mobile game.


(video : https://youtu.be/yiFklZVAUCM)

When the locked center cursor with proper raycast distance to the item, 'Hand button'  appears on GUI.
 
I have no idea after set to Settings manager - Hotspot detection method : Player Vicinity.
(added sphere collider as a child with Ignore Raycast layer) 

Or, is it appropriate method by Settings manager - Interface settings - Interaction method : Custom Script,
and then write a custom interaction script?

I would appreciate your advice!






Comments

  • A tutorial on "Player vicinity" Hotspot detection can be found here.  I'm not so sure it's necessary, however.

    If you check Lock cursor in screen's centre when game begins? (in the Setting Manager), then Hotspots will only be detected when in the centre of the screen.  You can stop distant Hotspots from being detected by reducing the Hotspot ray length value further down.

    To have the hand icon appear, you just need to create a new Menu that displays it, and have its Appear type set to On Hotspot.  Have the icon displayed as a Button element, and then set the Button's Click type set to Simulate Input.  Enter the Input axis as InteractionA (which doubles for a single-click on the Hotspot itself), and it should then trigger the interaction when tapped.

    Finally, to prevent tapping on the Hotspot / scene itself, create an "invisible" Menu that spans the screen area.  Just be sure to keep it at the top of the Menu stack, so that others are displayed/interacted with on top of it.
  • edited April 2018
    Thank you for your replying.

    I'm sorry but I can't find Lock cursor in screen's centre when game begins? setting in Touch Screen input method.

    If I set On Start Game ActionList - Player: Constrain - Cursor lock: Enable, Nothing happens when I tap the screen. All of touch don't work. (T_T)
  • Sorry, I didn't connect that you were using Touch Screen input.  The option is not available for that input mode.

    It may be that a custom script is necessary after all - I'll look into it.
  • All try, try this:

    Input method: Touch Screen
    Interaction method: Context Sensitive
    Hotspot detection method: Custom Script

    Then paste the following into a C# script named "AutoSelectCentreHotspot.cs", and attach it to a new GameObject in your scene:

    http://pasteall.org/938123/csharp

    Then create a new Menu to display your hand icon.  Set it's Appear type to On Hotspot, and make the hand icon with an Interaction element inside it.

    The script should select the centre-Hotspot for you regardless of the touch / cursor position, and the Menu should then turn on allowing you to press the Interaction icon to use the Hotspot.
  • edited April 2018
    Thank you so much, Chris.

    I also changed Interaction method: Custom Script and add some codes for my use button.


    ----------------
    using UnityEngine;
    using System.Collections;
    using AC;
    using UnityEngine.UI;

    public class AutoSelectCentreHotspot : MonoBehaviour
    {

    public float rayLength = 3f;

    public Hotspot hitHotspot = null;
    public GameObject handButton;

    void Update ()
    {
    if (KickStarter.stateHandler.IsInGameplay ()) {
    Ray ray = Camera.main.ScreenPointToRay (new Vector2 (Screen.width / 2f, Screen.height / 2f));
    RaycastHit hit;

    if (Physics.Raycast (ray, out hit, rayLength, 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer))) {
    if (hit.collider.gameObject.GetComponent <Hotspot> ()) {
    hitHotspot = hit.collider.gameObject.GetComponent <Hotspot> ();
    handButton.SetActive (true);
    } else {
    handButton.SetActive (false);
    }
    }
    }

    KickStarter.playerInteraction.SetActiveHotspot (hitHotspot);
    }

    public void UseInteraction()
    {
    hitHotspot.RunUseInteraction ();
    }
    }

    ---------------------------

    And I also added 'on click' function to hand button(Unity UI, not AC menu), which sends message "UseInteraction".

    I do not know if I've edited the code in the right way(I'm in a beginner level), but it works as i want!

    Thank you so much and I feel like I learned more through this time.

  • The use Interaction element menu should serve the same purpose without the need for manually enabling the hand button, but if it works it works!
  • Sorry, could I have this code again?

    "Then paste the following into a C# script named "AutoSelectCentreHotspot.cs", and attach it to a new GameObject in your scene:

    http://pasteall.org/938123/csharp"

    The link is missed now.

    Thank you

  • edited June 2021

    I don't have the original code, but it was along these lines:

    using UnityEngine;
    using AC;
    
    public class AutoSelectCentreHotspot : MonoBehaviour
    {
    
        public float rayLength = 3f;
    
        void Update ()
        {
            if (KickStarter.stateHandler.IsInGameplay ())
            {
                Ray ray = Camera.main.ScreenPointToRay (new Vector2 (Screen.width / 2f, Screen.height / 2f));
                RaycastHit hit;
    
                if (Physics.Raycast (ray, out hit, rayLength, 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer)))
                {
                    Hotspot hotspot = hit.collider.GetComponent<Hotspot> ();
                    if (hotspot)
                    {
                        if (KickStarter.playerInteraction.GetActiveHotspot () != hotspot)
                        {
                            hotspot.Select ();
                            hotspot.SetAsActive ();
                        }
                    }
                    else
                    {
                        if (KickStarter.playerInteraction.GetActiveHotspot ())
                        {
                            KickStarter.playerInteraction.GetActiveHotspot ().Deselect ();
                            KickStarter.playerInteraction.DeselectHotspot ();
                        }
                    }
                }
            }
            else if (KickStarter.playerInteraction.GetActiveHotspot ())
            {
                KickStarter.playerInteraction.GetActiveHotspot ().Deselect ();
                KickStarter.playerInteraction.DeselectHotspot ();
            }
        }
    
    }
    
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.