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 add collision Box to 2D irregular figure by NGUI in Unity3D

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you how to add collision boxes to 2D irregular graphics by NGUI in Unity3D. I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it.

To get to the point, clicking on a component in NGUI is very common, generally speaking, UIButton or UISprite, are regular graphics, it is very easy to click with NGUI, and there are many methods. But encounter special circumstances, such as making map plate click, are irregular graphics, you need to make a simple setting. Check some practices on the Internet, mostly by adding Polygon Collider2D irregular collision box with NGUI to send rays to achieve. However, the previous tutorials are earlier versions of NGUI, which need to add rays to send manually. Now I use NGUI version 3.9.8, which already includes the detection of 2D collision box. Here is a brief introduction to the process of using it.

1. Set Polygon Collider2D to an irregular object

2. Add UIButton components to this object (easy to test)

3. Change the Event Type of UICamera to 2D UI

4. Under the test, there is no response when the mouse is placed in the blank space of the picture after running.

When placed in the central area, the color change effect of the UIButton component is triggered, which proves that the collision box is triggered.

Finally: the above is the method of using NGUI to trigger after adding collision boxes to irregular objects. In NGUI's UICamera class under the Raycast method can be found to write this function, if your version of NGUI has this judgment or in the Unity editor with this option, then you can directly use, and then in the project with two cameras according to regular objects and irregular objects can achieve most of the desired effect.

The above is all the content of the article "how to add collision boxes to 2D irregular graphics by NGUI in Unity3D". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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