unity 衣服比对
时间: 2023-10-04 07:14:24 浏览: 104
根据提供的引用内容,unity 衣服比对是通过获取精灵(sprite)的点位信息,并与PolygonCollider2D的点位信息进行匹配,然后调整大小来实现的。具体方法是通过遍历PolygonCollider2D的Point点位,将其放大到与精灵的点位匹配。可以使用以下脚本实现该功能:
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
PolygonCollider2D poly2D;
Vector2[] pos_save; // 存放PolygonCollider2D的Point点位
public float scale = 100f;
void Start() {
poly2D = GetComponent<PolygonCollider2D>();
SetPos();
}
void SetPos() {
pos_save = poly2D.GetPath(0);
for (int i = 0; i < pos_save.Length; i++) {
pos_save[i *= scale;
}
poly2D.SetPath(0, pos_save);
}
}
```
将以上代码拖放到Unity中的一个物体上即可实现衣服比对的效果。这个脚本会获取PolygonCollider2D的点位信息,并将其放大到与指定精灵的点位匹配。您可以根据实际需求调整scale的值来控制放大的比例。该脚本适用于Unity的任何版本,只需将其放入Assets文件夹即可,无需额外操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Unity在UGUI上使用Polygon Collider 2D实现不规则图案匹配](https://blog.csdn.net/baidu_32519627/article/details/115488662)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Unity去除Unity Logo](https://download.csdn.net/download/a1062624730/87603933)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文