Unity ugui的鼠標穿透問題

可以用EventSystem.current.IsPointerOverGameObject()來判斷 ui上即爲true

或者用射線碰撞自己檢測每個canvas。

private bool  CheckUIRaycast() {

    PointerEventData eventData = new PointerEventData(EventSystem.current);
    eventData.pressPosition = Input.mousePosition;
    eventData.position = Input.mousePosition;

    List result = new List();

    EventSystem.current.RaycastAll(eventData, result);

    return result.Count > 0;
}

參考http://www.it165.net/pro/html/201506/43808.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章