- Home /
IsPointerOverGameObject doing the opposite of what I want
I am trying to prevent a the soldier in my RTS from moving towards the UI buttons when I click them. I used IsPointerOverGameObject and now my soldier won't move when I tap the screen and he only moves when I press the buttons. The exact opposite of what I want.
I tried putting a ! before IsPointerOverGameObject and the soldier did move when I tap the screen but he also moves when I press the button. I thought the not operand inverts things but it is not the opposite of what it was doing before.
here is my code: public class Movement : MonoBehaviour { NavMeshAgent agent;
private void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if (Input.touchCount > 0)
{
RaycastHit hit;
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = touch.position;
Ray ray = Camera.main.ScreenPointToRay(touchPosition);
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
agent.SetDestination(hit.point);
}
}
}
}
}
Your answer
Follow this Question
Related Questions
Button list from array 4 Answers
making and integrating Visual novel element in 3d game? 2 Answers
Gui Buttons multitouch 0 Answers
How can i keep this button pressed without acctualy doing it ? 0 Answers
Button Turns Off and On Object 1 Answer