Forum rules - please read before posting.

Issue when I use swipe to rotate the camera and the hotspot

Hi, I working in a escape room game and I don't have a player, but I have a room and I need rotate this room with a Swipe. I use Lean Touch for that, but I have issues because if I touch a hotspot it start the interaction (I think it is because is touch down). I want to know how I could I solve this with a tap event or touch up.

Comments

  • Welcome to the community, @gferrari.

    This is on a mobile device, I take it.

    Yes, interactions occur by default on the "touch down". However, it is possible to rely on a custom interaction system that instead reacts to touch releases.

    See the Manual's "Custom interaction systems" chapter for more details on this topic, but here's an example script. Set your game's Interaction method to Custom Script, and paste the following into a C# script named HotspotInteractionOnUp.cs:

    using UnityEngine;
    using AC;
    
    public class HotspotInteractionOnUp : MonoBehaviour
    {
    
        private void Update ()
        {
            if (KickStarter.stateHandler.IsInGameplay ())
            {
                if (Input.GetMouseButtonUp (0) || 
                    (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Ended))
                {
                    Hotspot hotspot = GetActiveHotspot ();
                    if (hotspot != null)
                    {
                        hotspot.RunUseInteraction ();
                    }
                }
            }
        }
    
        private Hotspot GetActiveHotspot ()
        {
            Ray ray = Camera.main.ScreenPointToRay (KickStarter.playerInput.GetMousePosition ());
            RaycastHit hit;
    
            if (Physics.Raycast (ray, out hit, KickStarter.settingsManager.hotspotRaycastLength, 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer)))
            {
                Hotspot hitHotspot = hit.collider.gameObject.GetComponent <Hotspot>();
                return hitHotspot;
            }
            return null;
        }
    
    }
    

    Attach this as a component to a new GameObject in your scene, and it should then cause Hotspots to have their "Use" interactions run when a tap is released.

  • Thanks so much!!

  • edited December 2019

    I'm a little embarrassed to ask again. It worked very well to activate the hotspot, but when I use an item it does not work with the hotspot and customscript.
    If you are in context sensitive this works.

    I try to do this but always I get null, Thanks for the patience...

              Hotspot hotspot = GetActiveHotspot();
                if (hotspot != null)
                {
                    hotspot.RunUseInteraction();
    
                    Debug.Log(KickStarter.runtimeInventory.SelectedItem);
    
                    if (KickStarter.runtimeInventory.SelectedItem != null)
                    {
                    hotspot.RunInventoryInteraction(KickStarter.runtimeInventory.SelectedItem);
    
                    }
                }
    
  • edited December 2019

    I made this and worked... because I use tap (With lean touch thirdparty component) to interact so if I use drag and drop in the inventory I need button up.

        if (KickStarter.runtimeInventory.SelectedItem != null && !isSelected)
        {
            selectedItem= KickStarter.runtimeInventory.SelectedItem; 
            isSelected = true;
    
        }
    
        if (Input.GetMouseButtonUp(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Ended))
        {
            Hotspot hotspot = GetActiveHotspot();
            if (selectedItem != null && hotspot != null)
            {
                hotspot.RunInventoryInteraction(selectedItem);
                selectedItem = null;
                isSelected = false;
            }
        }
       if (KickStarter.stateHandler.IsInGameplay())
        {
            if (isTap )
            {
                isTap = false;
                Hotspot hotspot = GetActiveHotspot();
                if (hotspot != null)
                {
                    hotspot.RunUseInteraction();
                }
    

    }

    I don't know if it is correct...

  • edited December 2019

    Generally SelectedItem should remain set when you expect it to be, but that may change if you're altering the way input is handled.

    One things you could do to reduce things a little would be to refer to LastSelectedItem instead of temporarily assigning the item in your own "selectedItem" variable.

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.