Skip to main content
4 of 7
added 803 characters in body
pguetschow
  • 191
  • 2
  • 12

Prevent Unity click go trough Canvas

I'm currently facing this problem: If I click on a Button on my Canvas, the currently selected Unit moves towards the location under the Button.

Is is there any option to solve this? I'm using the A* Project for this.

Sadly, I can not provide a lot of things I've done so far as I absolutely have no clue how to solve this problem.

If I disable the Button Option "Raycast Target" ist still moves to this position but holds a bit earlier.

Also, adding this as check didn't work:

if (!EventSystem.current.IsPointerOverGameObject() )

I also checked if the Raycast hit's the layer of the GUI

My Movement code so far:

public override void MouseClick(GameObject hitObject, Vector3 hitPoint, Player controller)
    {
        base.MouseClick(hitObject, hitPoint, controller);
        if (hasAuthority && player && player.human && currentlySelected)
        {
            if (hitObject.name == "Ground" && hitObject.name != "UI" && hitPoint != ResourceManager.InvalidPosition)
            {
                float x = hitPoint.x;
                float y = hitPoint.y + player.SelectedObject.transform.position.y;
                float z = hitPoint.z;
                destination = new Vector3(x, y, z);
                //Debug.Log("Start_Move");
                StartMove(destination);
            }
        }
    }
pguetschow
  • 191
  • 2
  • 12