Forum rules - please read before posting.

Disable Mousedown during HotspotEnter

Hi guys,

I want to attach a script to a gameobject of my choice, that once the mouse enters the hotspot area of that object, it won't be able to click on that hotspot area when the BuildonLocation script is running.

Do any of you have any idea how I could make that work?

I started out like this, but I feel that this is already way too much code for something small like my question:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC

public class DetectHotspotNoClick : MonoBehaviour
{
    public Hotspot hotspot;
    public bool OnHotspotEnter;
    public void OnHotspotOver()
    {
        EventManager.OnHotspotEnter += DetectHotspotClick;
    }
    public void DetectHotspotClick(Hotspot hotspot, Button button)
    {
        if (OnHotspotOver && hotspot == this.hotspot && button == hotspot.DetectHotspotClick()) ;
        {
            MouseOver.OnHotspotEnter = MouseDown(Disable);
        }
    }

}

Comments

  • Are you looking to disable a Hotspot while a custom script process is running?

    Sounds like it would be best to manipulate the Hotspot at the time the process starts and stops - rather than when the Player places the mouse over it.

    To turn a Hotspot on and off, you can call its TurnOn and TurnOff functions.

    When you call those functions would be based on how your BuildonLocation script works.

  • edited March 2021

    Hi Chris,

    Thanks for your quick reply.

    My intention is that I want to disable the mouse click function when hovering over an active hotspot, but only when a custom script is running.

    Now I think I can make the last part work. But I don't know how to disable the mouseclick (only) when hovering over an active hotspot.

    Context:
    I want to place buildings in a 2D environment, due to Chris' help we have made it that a player can place multiple buildings without error, but you can still place them on an occupied space. I want to make sure that you can't place a building when the space is already occupied.

    In short, I am actually looking for two parts:

    • disable the mouseclick when a custom script is running
    • disable the mouseclick when hovering over an active hotspot

    I'll then combine the two and voila :)

  • You can disable regular functionality for a mouse click by assigning an override to AC's InputGetMouseButtonDown function, which is AC's equivalent of Unity's Input.GetMouseButtonDown.

    See the Manual's "Remapping inputs" chapter for more on this topic, but here's an example script that lets you disable mouse clicks when the Inspector's "Disable mouse clicks" field is checked:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class InputDefine : MonoBehaviour
    {
    
        public bool disableMouseClicks;
    
    
        void Start()
        {
            KickStarter.playerInput.InputGetMouseButtonDownDelegate = CustomGetMouseButtonDown;
        }
    
    
        private bool CustomGetMouseButtonDown (int button)
        {
            if (disableMouseClicks)
            {
                return false;
            }
            return Input.GetMouseButtonDown (button);
        }
    
    }
    

    If that works as you intend, you can then see about replacing "disableMouseClicks" with your own conditions.

  • Hey Chris,

    Thanks for getting back! I'll look if I get this to work! Thank you for your help! I will read into Remapping Inputs as well, might learn a thing or two which I accidentally skipped over.

    I'll let you know how it goes. Thanks!

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.