2012-04-11 340 views

回答

3

這是不是你想要的?

http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html

**編輯**

using UnityEngine; 

public class example : MonoBehaviour 
{ 
    void Update() 
    { 
     // Left-half of the screen. 
     Rect bounds = new Rect(0, 0, Screen.width/2, Screen.height); 
     if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition)) 
     { 
      Debug.Log("Left!");    
     } 
    } 
} 
+0

它,但習慣於Input.GetMouseButtonDown(0)相當於鼠標左鍵點擊 – 2012-04-11 19:47:11

+0

這是否(編輯),爲你工作? – Lance 2012-04-11 20:00:35

+1

直到我使用Screen.height - Input.mousePosition.y作爲y鼠標位置時,這並不適用於我。出於某種原因,矩形的原點是左上角,而鼠標的原點是左下角。 – SystemicPlural 2014-03-10 12:43:26