I'm working in a game for mobile in which I can move the map with the finger. When I tap in some objects of screen it appears a UI text in scroll with information but when I touch the screen to do scroll in the text, the map placed in the background moves. How can I get the map doesn't move when I do scroll in the information text?
This is a screenshot:
This is the code to move the background map:
if(dragToPan){
if(!mapping && ready){
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved) {
if(Input.GetTouch(0).position.y > screenY/12){
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
//Check if any of the tile borders has been reached
CheckBorders();
//Translate the camera
cam.Translate(-touchDeltaPosition.x*dragSpeed*Time.deltaTime, -touchDeltaPosition.y*dragSpeed*Time.deltaTime, 0);
//Clamp the camera position to avoid displaying any off the map areas
ClampCam();
}
}
}
}
And this is how I enable the scroll text:
public class SeleccionarTesoro_LIST : MonoBehaviour {
void Start()
{
GameObject[] hitObject = GameObject.FindGameObjectsWithTag("TESOROS");
}
public void SetHitObjectToActive(GameObject hitObject)
{
hitObject.transform.GetChild(0).GetChild(0).gameObject.SetActive (true);
hitObject.transform.GetChild(0).GetChild(2).gameObject.SetActive (true);
}
void Update() {
if (Input.GetMouseButtonDown (0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit)) {
SetHitObjectToActive (hit.collider.gameObject);
}
}
}
}
UPDATE 1: I've added this lines in the first script and it works in Unity editor, but not in Android and iOS devices. How can I solve it?
if (EventSystem.current.IsPointerOverGameObject() ||
EventSystem.current.currentSelectedGameObject != null) {
return;
}