[英]Unity and C# click/touch over specific UI element check
我有一個代碼,如果我開始單擊或觸摸屏幕並拖動特定距離,它會執行某些操作。 我想檢查它何時位於特定區域上(讓我們說說UI,例如canvas)。 主要目標是讓屏幕的上半部分對單擊和觸摸做出反應。
我試圖通過創建新的Rect來做到這一點。 這可以,但是我不能在屏幕的上部制作矩形(現在它在屏幕的下部)。 我可能會丟失一些東西,但是下面的代碼應該在屏幕的上部創建rect,不是嗎?
if (Input.GetMouseButtonDown(0))
{
Rect bounds = new Rect(0, 0, Screen.height / 2, Screen.width);
if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition))
{
Debug.Log("Touchableee!");
TouchableArea = true;
}
if (TouchableArea == true)
{
tap = true;
isDraging = true;
startTouch = Input.mousePosition;
TouchableArea = false;
}
}
else if (Input.GetMouseButtonUp(0))
{
isDraging = false;
Reset();
}
任何想法都歡迎,謝謝...
您將在屏幕的底部啟動Rect,因此為什么它在屏幕的下半部分。
參數
x測量矩形的X值。
y測量rect的Y值。
width矩形的寬度。
height矩形的高度。
以下應該為您工作:
Rect bounds = new Rect(0, Screen.height, Screen.height / 2, Screen.width);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.