Unity2D:禁用了currentSelectedGameObject面板

时间:2016-10-02 13:43:29

标签: unity3d

好的,所以我点击移动游戏和一个我不希望我的玩家走向的面板。但是,面板首先被禁用(对于我正在做的效果),直到用户点击SetActive面板的按钮。我使用currentSelectedGameObject来阻止我的播放器进入面板,但是它没有工作,可能是因为面板首先被禁用,我不确定只是吐出想法。希望有人能帮助我。

using UnityEngine.EventSystems;

public GameObject currentSelectedGameObject;

public void Update () {
        if (Input.GetMouseButtonDown (0)) {
        if (EventSystem.current.currentSelectedGameObject)
            return;
                    Vector3 mousePosition = Input.mousePosition;
                    mousePosition.z = 10; // distance from the camera
                    target = Camera.main.ScreenToWorldPoint (mousePosition);
                    target.z = transform.position.z;
    }

                    transform.position = Vector3.MoveTowards (transform.position, target, speed * Time.fixedDeltaTime);
   }

谢谢。 :)

1 个答案:

答案 0 :(得分:0)

使用按钮设置面板,如果没有,则不在代码中使用公共GameObject currentSelectedGameObject变量,执行以下操作:

if (EventSystem.current.currentSelectedGameObject == currentSelectedGameObject) // now this is your variable that you declared being used in the if statement

我无法正确记住,但它就像这个EventSystem.current.currentSelectedGameObject.name