Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to shield unity response events

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to shield unity response events". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Shielding UI response events in the 3D World

In Unity game development, we often encounter such a problem: drag and drop 3D scenes to preview the current world. That is, by dragging the mouse to control the position of the camera. But in the scene, there is usually a UI interface suspended at the top.

When we swipe the scroll list on the UI interface, we will find that the scene will move with it. This is what we don't want to see. The correct result should be that the camera does not move until you drag the scene, which is in line with our settings. Therefore, an interface is needed to determine whether the current mouse is clicked on the UI.

Public bool IsPointerOverGameObject ()

{

If (Input.GetMouseButton (0)

| | (Input.touchCount > 0 & & Input.GetTouch (0). Phase = = TouchPhase.Began))

{

# if UNITY_EDITOR

If (EventSystem.current.IsPointerOverGameObject ())

Return true

# else

If (Input.touchCount > 0)

{

Int fingerId = Input.GetTouch (0). FingerId

If (EventSystem.current.IsPointerOverGameObject (fingerId))

{

Return true

}

}

# endif

}

Return false

}

If the function interface above returns true, it indicates that the current mouse has clicked UI.

That's all for the content of "how to block unity response events". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report