Forum rules - please read before posting.

Rotatable inventory object with Clicking Menu interaction to wait for drag/click select

I had selected interaction style as Choose Hotspot then interaction and then right click cycling of the interaction cursor. However testers didn't like all the clicking, since some interactions of a hotspot also open and close during game play. So I want to have a menu that opens with all interactions shown with first click. This is a problem with the present inventory items though. All the items also have a hotspot on its main body, so there will be at least a Look-at.

What I would like to have is a delayed reaction inside inventory so, that it would only open after this grab minimum time is passed. Here's a pic: https://imgur.com/a/f4EUsRe .

I have an inventory with rotatable items that may have several hotspots and several interactions with them. The item are placed in front of the inventory camera when player clicks inventory menu icon. All items are rotatable. Hotspot interactions don't have ALs linked, but there is a script that has a OnGrabMoveable delegate. OnHotspotInteract will take a note of Hotspot clicked and the interaction cursor, and OnDropMoveable will detect if player ends grab within 0.2 secs and this is then considered a click and then fire hotspot interaction.

Here's the main code parts:

    void OnDropMoveable (DragBase dragBase)
    {
        if (dragBase == draggable)
        {
            if ((Time.time - grabTime) <= maxTimeForHotspotClick)
            {
                RaycastHit hit;
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast (ray.origin, ray.direction, out hit, 20.0f) ) {
                    selected = hit.collider.gameObject.name;

                    switch (selected) {
                        case "Two_way_radio":
                            if (myInteraction.Item1 == InvHelp.Interaction.LOOK_AT) {
                                Debug.Log("Two_way_radio LOOK_AT");
                                MainObject();
                            }
                            break;
                        case "Two_Way_Radio_Battery_Door":
                            if (myInteraction.Item1 == InvHelp.Interaction.LOOK_AT) {
                                Debug.Log("Two_Way_Radio_Battery_Door LOOK_AT");
                            }
                            if (myInteraction.Item1 == InvHelp.Interaction.USE) {
                                Debug.Log("Two_Way_Radio_Battery_Door USE");
                                BatteryCover();
                            }
                            if (myInteraction.Item1 == InvHelp.Interaction.INVENTORY) {
                                Debug.Log("Two_Way_Radio_Battery_Door INVENTORY - " + "x " + myInteraction.Item2 + " x");
                                PutBatteryIn();
                            }
                        break;                    
                    }
                }
            }
        }
    }

void OnHotspotInteract (Hotspot hotspot, AC.Button button) {
    InvHelp.Interaction myIH = (InvHelp.Interaction) button.iconID;
    if (hotspot.GetButtonInteractionType (button) == HotspotInteractionType.Inventory) myIH = InvHelp.Interaction.INVENTORY;
    bool isInventory = (hotspot.GetButtonInteractionType (button) == HotspotInteractionType.Inventory);
    string invItem = isInventory ? KickStarter.inventoryManager.GetLabel(button.invID) : "";

    myInteraction.Item1 = myIH;
    myInteraction.Item2 = invItem;
}

void OnGrabMoveable (DragBase dragBase)
{
    if (dragBase == draggable)
    {
        grabTime = Time.time;
    }
}

Comments

  • edited April 2022

    If you want to delay the opening of an Interaction menu, you'll need to open it manually through custom script at the correct time:

    KickStarter.playerMenus.EnableInteractionMenus (myHotspot);
    

    However, the OnHotspotInteract event is only triggered once an Interaction has been chosen. In this case, this would be done by clicking an Interaction element inside the Interaction menu.

    What you could do instead is to have each of the Hotspots that appear on an Item be turned into a pair of Hotspots: one that is on the Hotspot itself (and clicked by the player), and another that is used to house all of the Interactions that the Menu should show.

    The first Hotspot would be a "dummy" Hotspot that only serves to detect the Player's initial click. If it has Single 'Use' Interaction? checked, then clicking it will run the OnHotspotInteract event without use of a Menu. Instead of the above script then recording that same Hotspot, it could instead store that Hotspot's "paired Hotspot", so that it can later open its Interaction menu. The relation between the "dummy" and "paired" Hotspot could be created by parenting one to the other.

    Something like:

    Hotspot hotspotWithInteractionMenu;
    void OnHotspotInteract (Hotspot hotspot, AC.Button button)
    {
        if (hotspot.gameObject == gameObject)
        {
            hotspotWithInteractionMenu = hotspot.GetComponentInChildren<Hotspot> ();
        }
        else
        {
            hotspotWithInteractionMenu = null;
        }
    }
    
    void OnDropMoveable (DragBase dragBase)
    {
        if (dragBase == draggable && (Time.time - grabTime) <= maxTimeForHotspotClick && hotspotWithInteractionMenu)
        {
            KickStarter.playerMenus.EnableInteractionMenus (hotspotWithInteractionMenu);
        }
        hotspotWithInteractionMenu = null;
    }
    
  • I get the menu to pop up, but can't get it to work. It seems that the buttons do not point to correct ALs, or maybe any ALs.

  • I'm getting all the right options in the menu, but no action.

  • Oh, it was just a small bug. Now it works perfeclty.

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.