2013-01-17 42 views
0

我做了滾動查看。當我滾動視圖時,下面的場景也會作出迴應。當觸摸GUI的區域時,只有gui事件響應?

如何使它只有當觸摸GUI組件的區域

+0

[防止鼠標點擊通過gui](http://answers.unity3d.com/questions/16774/preventing-mouse-clicks-from-passing-through-gui-c.html)&& [如何使用GUI實用程序hotControl](http://answers.unity3d.com/questions/320344/how-to-use-guiutilityhotcontrol.html)也許有用 – Maadiah

回答

0
private float scroll_value; 
private Rect vscroll_rect = new Rect(0,0,100,100); 
void OnGUI() { 
    scroll_value = GUI.VerticalScrollbar (vscroll_rect , scroll_value, 1.0f, 0.0f, 10.0f); 
} 
void Update() { 
    // Cursor is inside verticalscroll rect, ignore it 
    if (vscroll_rect.Contains(Input.mousePosition))return; 
} 

唯一的問題是,如果你有很多不同的腳本幾個GUI元素,他們每個人都需要,如果Input.mouseCursor測試響應GUI事件在GUI元素中。一個簡單的方法就是創建一個腳本來管理GUI rects,您可以從任何其他腳本調用該腳本來檢查。