2016-10-02 62 views
0

好的,所以我有一個點擊來移動遊戲和一個我不希望我的玩家移動的面板。然而,面板最初是禁用的(對於我所做的一個效果),直到用戶點擊一個按鈕來設置面板。我使用currentSelectedGameObject來阻止我的播放器進入面板,但它不起作用,可能是因爲面板首先被禁用,我不確定是否只是吐出了想法。有希望的人可以幫助我。Unity2D: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); 
    } 

謝謝。 :)

回答

0

使用按鈕SETACTIVE面板,如果不是,你是不是在你的代碼中使用公共遊戲物體currentSelectedGameObject變量,這樣做:

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

我不能記錯,但mb個其像這樣的EventSystem .current.currentSelectedGameObject.name

+0

謝謝你的建議,但我沒有真正的工作 –