LoginSignup
9
9

More than 5 years have passed since last update.

Unity ボタンのクリックと画面のタップを排他制御する。

Last updated at Posted at 2016-02-26

 ■下記ページを参照しました、めっちゃ助かりました。
 http://denshikousaku.net/unity-memo-4

 ■return results.Count > 0の部分はいろいろ検討の余地あり、
 テクスチャーが裏に1枚入れば、
 それだけでカウントは1になる。

/// <summary>
/// タップ位置にオブジェクトが存在するか?
/// </summary>
/// <returns></returns>
private bool IsPointerOverUIObject()
{
    PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
    eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

    List<RaycastResult> results = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
    return results.Count > 0;
}


void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        if (!IsPointerOverUIObject())
        {
            // タップ位置に何も存在しない
        }
    }
}
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9