-1

https://i.stack.imgur.com/06qKC.jpg. (screenshot of my game)

When I click on the Upgrade or Sell button the turret behind it gets "enabled". How can I change that ? (It's a mobile game with touch input). Is there any code I should implement oder can I simply change that in the inspector?Thanks for your answers :)

Oliver
  • 1
  • You need to change the way you detect touch/click on the 3D object. Use the `EventSystems`. See "6.For 3D Object (Mesh Renderer/any 3D Collider)" from the answer in the duplicated question. You can also use `EventSystem.IsPointerOverGameObject` but that's only a workaround. – Programmer May 03 '17 at 08:23

2 Answers2

1

Try checking by using this first..

public static bool IsPointerOverUIObject() {
    PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
    eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
    List<RaycastResult> results = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
    return results.Count > 0;
}
Ben Brookes
  • 419
  • 4
  • 15
0

Try checking the Raycast Trigger on the UI Image, it should block the raycasts and mouse click too. Here is documentation reference

Dávid Florek
  • 552
  • 6
  • 17