很简单 但又一时想不起来的功能合集

 

/// <summary>

/// 根据模型的尺寸 取得的模型边缘位置与模型中心的相对位置 (在不适用物理的情况下 模型移动式避免穿模)
/// </summary>

var bounds = GetComponent<MeshRenderer>().bounds;
var size = bounds.max - bounds.min;
_offset = transform.position - bounds.center+ new Vector3(0, bounds.size.y/2,0);

 

/// <summary>
/// 设置游戏区域 (设置空气墙)
/// </summary>
/// <param name="nothing"></param>
private void onSizeChange(object[] nothing)
{

//存放空气墙的数组

 BoxCollider[] Colliders; 

 //屏幕上四个点

 Vector3[] GameArea= new Vector3[] {

camera.WorldToScreenPoint(BorderTop.transform.position),
camera.WorldToScreenPoint(BorderBottom.transform.position),
camera.WorldToScreenPoint(BorderLeft.transform.position),
camera.WorldToScreenPoint(BorderRight.transform.position) };

 

var camera = GameFrameEntry.GetModule<UIModule>().UICamera;
  

Vector3[] poses = GameArea;
if (poses == null) return;
var topPos = screenToPlaneProjection((Vector3)poses[0]);
var botPos = screenToPlaneProjection((Vector3)poses[1]);
var leftPos = screenToPlaneProjection((Vector3)poses[2]);
var rightPos = screenToPlaneProjection((Vector3)poses[3]);
Colliders[0].transform.position = topPos;
Colliders[1].transform.position = botPos;
Colliders[2].transform.position = leftPos;
Colliders[3].transform.position = rightPos;
Colliders[4].transform.position = topPos;

}

posted @   真的勇士  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示