Ok, I have this Canvas with 3 buttons.
When i touch 1 button (mean Throttle) in console output name of GameObject (ThrottleButton). It’s correct.
Same on 3 button. But if i click on 2 ui element ( it’s part of “Simple Joystick Pack”) in console output Null.
i.e. if i click on 2 button EventSystem.current.currentSelectedGameObject is Null.
This has nothing to do with button component. Object under your finger are detected using UI raycaster and it have a ruleset to determine if there’s object or there’s not. For example, that (2) object may contain a canvas group marked as non-interactable, or there migh be other reasons. It hard to tell without knowing that component you use, but you may chek EventSystem.current.RaycastAll method results to see what object are detectable.
// Условие для проверки того, попал ли тач в интерфейс и в какой именно.
// Если тачей больше 0, то для каждого тача проверяется, прошел ли он через UI
// Если да, то проверяется что это за UI элемент с помощью EventSystem.current.RaycastAll
// Если это нужная кнопка - то делаем действия, например увеличиваем тягу или делаем поворот
if ( Input.touchCount > 0 )
{
foreach ( Touch touch in Input.touches )
{
if ( EventSystem.current.IsPointerOverGameObject( touch.fingerId ) )
{
PointerEventData pointer = new PointerEventData(EventSystem.current);
pointer.position = touch.position;
List<RaycastResult> raycastResults = new List<RaycastResult>();
EventSystem.current.RaycastAll( pointer, raycastResults );
if ( raycastResults.Count > 0 )
{
foreach ( var go in raycastResults )
{
Debug.Log(go.gameObject.name);
}
}
}
}
}