Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

EventSystem issue...

Discussion in 'Unity 5 Pre-order Beta' started by Ziron999, Mar 3, 2015.

  1. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    282
    in 4.6 this worked great:
    Code (CSharp):
    1. if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.GetComponent<Button>() != null)
    2.                 return; //clicked button
    3.             else
    4.             {
    5.                 if (Input.GetMouseButtonDown(0) && Input.touchCount != 2)
    6.                 {
    7.                     MoveToMouse();
    8.                 }
    9.                 if (Input.GetMouseButton(0) && !RTSCamera.dragging && !planetSelected)
    10.                     Invoke("MovePlayerToDestination", 0.2f);
    11.                 else if(RTSCamera.dragging)
    12.                     CancelInvoke("MovePlayerToDestination");
    13.             }
    however in 5 for some reason when i push a button from the UI it still doesn't trigger anymore and you push behind it :(
     
  2. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    282
    It appears to be an issue with EventSystem.current.currentSelectedGameObject.GetComponent<Button>() != null) it looks like in 5 no matter what get button is never null even if the gameobject doesn't have one...

    even trying mouse over like so:
    Code (CSharp):
    1. if(EventSystem.current.currentInputModule is TouchInputModule) {
    2.                 for(int i=0; i<Input.touchCount; i++) {
    3.                     Touch touch = Input.touches[i];
    4.                     if( touch.phase != TouchPhase.Canceled && touch.phase != TouchPhase.Ended) {
    5.                         if(EventSystem.current.IsPointerOverGameObject( Input.touches[i].fingerId )) {
    6.                             if (EventSystem.current.currentSelectedGameObject.GetComponent<Button>() != null)
    7.                             {
    8.                                 Debug.Log(EventSystem.current.currentSelectedGameObject.name);
    9.                                 isPointerOverGameObject = true;
    10.                             }
    11.                             break;
    12.                         }
    13.                     }
    14.                 }
    15.             } else {
    16.                 isPointerOverGameObject = EventSystem.current.IsPointerOverGameObject();
    17.             }
    isPointerOverGameObject = true even when over objects without a button :(
     
  3. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    282
    never mind this issue was due to the script execution order changing