Skip to main content
fixed typos, left aligned code block
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

Prevent Unity click gofrom going through 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" istit 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'shits 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);
            }
        }
    }

Prevent Unity click go through 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);
            }
        }
    }

Prevent Unity click from going through 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" it 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 hits 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);
        }
    }
}

Prevent Unity click go troughthrough Canvas

deleted 74 characters in body
Source Link
pguetschow
  • 191
  • 2
  • 12

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);
            }
        }
    }

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);
            }
        }
    }

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);
            }
        }
    }
Tweeted twitter.com/StackGameDev/status/806473486583681024
added 803 characters in body
Source Link
pguetschow
  • 191
  • 2
  • 12
Loading
added 60 characters in body
Source Link
pguetschow
  • 191
  • 2
  • 12
Loading
added 108 characters in body
Source Link
pguetschow
  • 191
  • 2
  • 12
Loading
Source Link
pguetschow
  • 191
  • 2
  • 12
Loading