Forum rules - please read before posting.

Can't detect mouse clicks when hovering over hotspots and clicking.

edited June 2015 in Technical Q&A
I'm using this little script to detect right clicks and I can't get them if I hover over hotspots and right click. Outside of the hotspots is fine though.

void OnMouseOver ()
{
 if(Input.GetMouseButton(1))
   {
     Debug.Log ("Test"):
  }
}

Basically I need this to dismount my sprite from mouse cursor.

Since there is no feature in AC to have an object follow mouse in a manner of as if you replaced mouse cursor image for another image. The other AC feature to follow mouse as a character or NPC won't do since it is kind of with a delay factor.

And I need an object/my sprite to move as if you replaced the cursor image.
So I make my sprite follow the mouse in my custom script but I need it to stop, thus I need to detect right click mouse, and It doesn't work if the mouse is hovering over hotspots.

Comments

  • In the Cursor Manager, you can render your cursors Hardware, rather than Software - this avoids swapping out the mouse with a texture.

    It may be that your script is being executed after AC's PlayerInput script.  Try altering it's order in Unity's Script Execution Order panel.
  • Tried both, still can't get the right click when hovering over a Hotspot, only left click.

    Also tried to include in the order other scripts AC.DetectHotspots, AC.PlayerCursor, AC.PlayerInteraction, AC.Hotspot, AC.Interaction  beneath mine script.
  • Thinking about this more, the Input.GetMouseButton call should still work in conjunction with AC's input scripts.  The key thing instead is to focus on the cursor's position - as you said, it can end up being in a different spot.

    You can retrieve the cursor's position with:
    AC.KickStarter.playerInput.GetMousePosition ();

    And then use it in your code.. In fact, the PlayerInteraction script's CheckForHotspots() function is how AC determines what Hotspots are under the cursor - you may find it useful to pick it apart.
  • Chris,I just found out, why Hotspots get activated on both mouse buttons clicks? Shouldn't there be just left button usage?
    Is there an option to limit only to left button and leave the right button for diselect, how? 
  • edited June 2015
    Post a screenshot of your Settings Manager - I'll need to see your Interaction settings.
  • There it is :
    image
    image
  • You can prevent right-clicks on Interaction icons from working by inserting the following into the top of the MenuInteraction script's ProcessClick function (line 227):

    if (_mouseState == MouseState.RightClick)
    {
       return;
    }
  • edited June 2015
    You mean line 277-278 with this? :

    public override void ProcessClick (AC.Menu _menu, int _slot, MouseState _mouseState)
                          {
                             if (KickStarter.stateHandler.gameState == GameState.Cutscene)                                                            {
                                                 return;
                                        }
                                        KickStarter.playerInteraction.ClickInteractionIcon (_menu, iconID);
                                    }
                 }

    Tried to insert it everywhere still can right click on hostpots.
  • It should go just after the first curly brace.

    I was referring to right-clicking on Interaction icons, however - right-clicking on Hotspots should only work for Context Senstive mode, not for Choose Hotspot Then Interaction.  The only way I could see that happening is if you mapped the right-mouse button to the InteractionB input axis.

    Insert the code below into line 292 of PlayerInteraction.cs.  Let me know what the console says when you right-click on a Hotspot.

    Debug.Log (KickStarter.playerInput.mouseState + " " + KickStarter.runtimeInventory.selectedItem + " " + KickStarter.runtimeInventory.hoverItem);
  • edited June 2015
    Huh, I changed Interaction method to Choose interaction then Hotspot.
    Now it is perfect I can't right click on the hotspots :)
    Thanks Chris!
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.