i just started to get into mobile inputs.
i’ve learned to check if I’m touching the UI or not but I can’t find how could I get it so I know what UI element I actually are touching (ex. image, text…).
i just started to get into mobile inputs.
i’ve learned to check if I’m touching the UI or not but I can’t find how could I get it so I know what UI element I actually are touching (ex. image, text…).
You can get EventSystem.current
and change the position to touch position. Then all the raycasts you get with the RaycastAll
function will give you the gameObjects that you are currently touching.
public bool TouchOnTrashButton ()//if touch phase ends on this button
{
//than the function will return true
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y);
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
if (results.Count > 0)
{
if (results[0].gameObject.name.Equals("TrashCanGFX"))
{
return true;
}
}
}
return false;
}
Thank you @Keary worked perfectly.
© 2022 - 2024 — McMap. All rights reserved.