Forum rules - please read before posting.

Trigger action on any mouse click

Hi! Total noob here just starting with both AC and Unity. Great plugin, btw! But I got stuck on a silly thing that is likely very easy to do, and I would appreciate the help.

I want my character to have a situation where pressing a button forces him click on one of available items in a room to trigger some script with them, or to click anywhere else and for that to also be considered a choice. But I have a problem with the last one. Is there an easy way to register a random click during gameplay?

I tried putting "Input:Check for single click" on a button that activates all this, but I think that counts the very click you make on a button as click it needs. And even if you add waiting before it that just stops the game until you make a click - you can't interact with anything until you do and thus cant make a choice.

I also tried to create a huge trigger over the whole screen with the same input checks but it mostly did the same. And a giant red rectangle also kinda gets in the way while working )

Comments

  • Welcome to the community, @RPRezo.

    By button, are you referring to a menu button, or a Hotspot in the scene?

    It's possible to define Active Inputs, which run ActionLists when a given input is pressed (see the Manual's "Active Inputs" chapter for details), but this will override any clicks that occur over Hotspots.

    If you want to distinguish between clicks on regular Hotspots in your scene vs anywhere else, having a large Hotspot that spans the screen isn't a bad option. You shouldn't need to use any special Input: Check Action - just a Hotspot with a single space character (" ") for its label should be enough to make it appear hidden.

    To prevent the giant yellow rectangle from showing up in your Scene window, uncheck Draw yellow cube? in the Hotspot's Inspector.

    It's also possible to do this in script, by checking if the mouse is currently over a Hotspot or Menu, and running an ActionList if not:

    using UnityEngine;
    using AC;
    
    public class EmptySpaceClick : MonoBehaviour
    {
    
        public ActionList actionList;
    
        private void Update ()
        {
            if (Input.GetMouseButtonDown (0) && KickStarter.stateHandler.IsInGameplay () && KickStarter.runtimeInventory.SelectedItem == null)
            {
                // Clicked during gameplay, with no item selected
                if (KickStarter.playerInteraction.GetActiveHotspot () == null && !KickStarter.playerMenus.IsMouseOverMenu ())
                {
                    // No active Hotspot or menu
                    actionList.Interact ();
                }
            }
        }
    
    }
    

    To go with this option, copy/paste this code into a C# file named EmptySpaceClick and add it to a GameObject in your scene. Assign the "Action List" field in its Inspector, which should be run whenever the Player clicks in empty space during gameplay.

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.