触摸滚动UI文本干扰背景地图

时间:2018-05-16 12:06:45

标签: c# unity3d

我在移动游戏中工作,我可以用手指移动地图。当我点击某些屏幕对象时,会出现一个带有信息滚动的UI文本,但是当我触摸屏幕以在文本中滚动时,放置在背景中的地图会移动。当我在信息文本中滚动时,如何才能使地图移动?

这是截图:

enter image description here

这是移动背景地图的代码:

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();
                }
            }
        }   
    }           

这就是我启用滚动文本的方式:

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);
            }

        }
}
}

更新1:我已在第一个脚本中添加了这些行,它在Unity编辑器中有效,但在Android和iOS设备中无效。我该如何解决?

if (EventSystem.current.IsPointerOverGameObject() ||
        EventSystem.current.currentSelectedGameObject != null) {
        return;
    }

1 个答案:

答案 0 :(得分:1)

如果您希望以这种方式继续,您可以尝试在后台移动器脚本中使用bool变量 isUIActive ,可以从其他脚本中设置为false或true,并且只要文本获得active将其设置为true,并且每当禁用UI时将其设置为false。 在检查背景移动的输入之前,还要检查 isUIActive

这样的事情:

if (!isUIActive){
    if(dragToPan){
        if(!mapping && ready){
            ...

和设置变量的函数:

public void SetUIActive (bool setTo){
     isUIActive = setTo;
}

在您需要的地方,您可以调用此功能并进行设置。 请注意,要在其他脚本中使用此脚本的引用。 如果这有帮助,请告诉我。