Search Unity

How to create interactable for a 2D Point and Click without conflict with movement click

Discussion in '2D' started by DexDrakon, Jul 30, 2019.

  1. DexDrakon

    DexDrakon

    Joined:
    May 20, 2019
    Posts:
    2
    Hello fellas!

    I'm creating a 2D adventure/point and click in Unity where the character's movement is based in transform.position to a vertical point of the mouse click with a variable that I call targetPosition.

    targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition)

    But I'm having trouble when I started to create the first interactable because the targetPosition is 'conflicting' with the interactable collider (I'm using OnMouseDown to detect the collider with a click). The player just moves to the point of "targetPosition", without interact with the "button". As a test, I disabled the movement input (Input.GetMouseButton) and click in interactable collider and it works (but just alone).

    The core idea is: If I click on any interactable, the player goes to there, not because of targetPosition, but for the variable "locationPoint" of the interactable, and activates the "button" when the character gets there.

    But I'm new with codes and Unity and have no clue how to do that. I searched in a lot of threads in here and in YouTube tips but no help. I remember to have seen something about Event Trigger, but I can't make it work.

    Please, help with this!