Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Prevent screentoworldpoint to execute while clicking on UI object

Discussion in 'Scripting' started by FalconJ, Jan 20, 2016.

  1. FalconJ

    FalconJ

    Joined:
    Mar 12, 2015
    Posts:
    146
    I'm creating a point adventure game in which the character can move through the use of screenToWorldPoint.
    However, I also put an UI object (such as pause button) on the same screen. The issue persist when I clicked on the UI object, the character also moves to the position where I clicked on the UI.
    I want to prevent the gameObject while I'm only clicking the UI object. Is there any other way to achieve this?
     
  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Post the code you're using to move your character based on the click. If you know you're hitting a UI element, you shouldn't even be telling the character to try to move!
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Well, I'm betting there's more than 'screenToWorldPoint'... I'm assuming you're calculating this value on some event. May it be in Update you check for mouse down, or by implementing the 'OnMouseDown' message, or something. Where as the UI is probably on some other types of events, may it again be the 'OnMouseDown', or using the EventSystem events, or something else.

    Your problem is that both events are occurring at the same time.

    With out knowing how you actually implemented it, it's hard for us to give you any direction as to how to block one from occurring when the other does.