当前位置: 首页 > news >正文

洛阳建网站公司电商培训基地

洛阳建网站公司,电商培训基地,光之翼可以做网站吗,律师行业网站模板文章目录 1. 定义2. 重要类和方法2.1 Ray2.2 从屏幕发出射线:2.3 Raycast2.4 RaycastAll2.5 RaycastHit 碰撞信息2.6 layerMask 让射线检测只检测指定层级的对象 1. 定义 在Unity中,射线检测(Raycasting)是一种常用的技术&#x…

文章目录

  • 1. 定义
  • 2. 重要类和方法
    • 2.1 Ray
    • 2.2 从屏幕发出射线:
    • 2.3 Raycast
    • 2.4 RaycastAll
    • 2.5 RaycastHit 碰撞信息
    • 2.6 layerMask 让射线检测只检测指定层级的对象

1. 定义

在Unity中,射线检测(Raycasting)是一种常用的技术,用于检测射线是否与场景中的物体相交。这在游戏开发中用于实现点击物体、射线武器的碰撞检测、角色与环境的交互等方面非常有用。

2. 重要类和方法

2.1 Ray

定义:表示从一个点沿着特定方向延伸的虚拟线段
属性:

  • direction 射线的方向。
  • origin 射线的原点。

构造函数:

public Ray (Vector3 origin, Vector3 direction);

在场景中绘制射线(仅在 Debug 下可见):

 // 创建射线
Ray ray = new Ray(Vector3.zero, Vector3.forward);// 在场景中绘制射线,可选操作(仅用于调试目的)
Debug.DrawRay(ray.origin, ray0.direction * 10f, Color.red);

2.2 从屏幕发出射线:

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

void Update()
{if (Input.GetMouseButton(0)) {Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);Debug.DrawRay(ray.origin, ray.direction * 10f, Color.red);}}

2.3 Raycast

定义:射线检测获取相交的单个物体,它可以检测射线是否与某个物体相交,如果相交,还可以获取有关交点的信息

bool Raycast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask);
参数含义:
Ray——射线对象
RaycastHit——碰撞(相交)对象信息
maxDistance——射线检测的最大距离
layerMask——层蒙版(用于只检测特定层对象)
返回值含义:
bool——当射线和物体相交时返回true

void Update()
{if (Input.GetMouseButtonDown(0)) {Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit hitInfo;if (Physics.Raycast(ray, out hitInfo)){// 射线与物体相交Debug.Log($"Name:{hitInfo.collider.name},Point:{hitInfo.point}");}}
}

在这里插入图片描述

2.4 RaycastAll

定义:射线检测获取相交的多个物体
RaycastHit[] RaycastAll(Ray ray, float maxDistance, int layerMask);
RaycastHit[]——当射线和物体相交时,返回相交的物体们,如果没有碰撞到,数组长度为0

void Update()
{if (Input.GetMouseButtonDown(0)) {Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit[] hitInfos;hitInfos = Physics.RaycastAll(ray, int.MaxValue);// 射线与物体相交foreach (var item in hitInfos){Debug.Log($"Name:{item.collider.name},Point:{item.point}");}       }
}

在这里插入图片描述

2.5 RaycastHit 碰撞信息

在这里插入图片描述

2.6 layerMask 让射线检测只检测指定层级的对象

LayerMask.NameToLayer(层名):根据层名字转换为层编号的方法
层编号:
在这里插入图片描述
1 << LayerMask.NameToLayer(“Cube”)

void Update()
{if (Input.GetMouseButtonDown(0)) {Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit hitInfo;// 1 << LayerMask.NameToLayer("Cube") 将 1 左移得到的层级编号位数,得到层级编号的二进制if (Physics.Raycast(ray, out hitInfo, int.MaxValue, 1 << LayerMask.NameToLayer("Cube"))){// 射线与物体相交Debug.Log($"Name:{hitInfo.collider.name},Point:{hitInfo.point}");}}
}

在这里插入图片描述


文章转载自:
http://imperceivable.c7510.cn
http://mlf.c7510.cn
http://faeces.c7510.cn
http://multivolume.c7510.cn
http://bedlight.c7510.cn
http://monostrophic.c7510.cn
http://figuresome.c7510.cn
http://perfidiously.c7510.cn
http://aerie.c7510.cn
http://lycanthrope.c7510.cn
http://unspiritual.c7510.cn
http://abustle.c7510.cn
http://mazel.c7510.cn
http://thereanent.c7510.cn
http://spilehole.c7510.cn
http://optoacoustic.c7510.cn
http://factualism.c7510.cn
http://tu.c7510.cn
http://triethyl.c7510.cn
http://orthognathous.c7510.cn
http://commenter.c7510.cn
http://scorbutic.c7510.cn
http://litoral.c7510.cn
http://octu.c7510.cn
http://foxglove.c7510.cn
http://humidifier.c7510.cn
http://usually.c7510.cn
http://rheogoniometry.c7510.cn
http://airtel.c7510.cn
http://unobscured.c7510.cn
http://coadapted.c7510.cn
http://scintiscan.c7510.cn
http://bellhop.c7510.cn
http://aspish.c7510.cn
http://algernon.c7510.cn
http://saturdays.c7510.cn
http://irreparability.c7510.cn
http://studious.c7510.cn
http://entoutcas.c7510.cn
http://antibacterial.c7510.cn
http://varlet.c7510.cn
http://hypnodrama.c7510.cn
http://timelike.c7510.cn
http://inodorous.c7510.cn
http://nonparticipating.c7510.cn
http://radiographer.c7510.cn
http://nardu.c7510.cn
http://coxy.c7510.cn
http://chrysalid.c7510.cn
http://sufficiency.c7510.cn
http://buprestid.c7510.cn
http://tiber.c7510.cn
http://clobberer.c7510.cn
http://inexpedient.c7510.cn
http://swayless.c7510.cn
http://baba.c7510.cn
http://vinton.c7510.cn
http://semilanceolate.c7510.cn
http://guicowar.c7510.cn
http://tangleweed.c7510.cn
http://qse.c7510.cn
http://glorious.c7510.cn
http://contortive.c7510.cn
http://totipalmate.c7510.cn
http://vend.c7510.cn
http://streak.c7510.cn
http://crispation.c7510.cn
http://diplomatise.c7510.cn
http://balaclava.c7510.cn
http://railfan.c7510.cn
http://dormeuse.c7510.cn
http://referential.c7510.cn
http://kennebec.c7510.cn
http://unprized.c7510.cn
http://bedbound.c7510.cn
http://woodenness.c7510.cn
http://catenoid.c7510.cn
http://paisan.c7510.cn
http://earthman.c7510.cn
http://diphtheria.c7510.cn
http://amalgam.c7510.cn
http://spreadover.c7510.cn
http://toothcomb.c7510.cn
http://ripen.c7510.cn
http://firetrap.c7510.cn
http://cafeteria.c7510.cn
http://coachwood.c7510.cn
http://burghley.c7510.cn
http://ragtag.c7510.cn
http://worthless.c7510.cn
http://unclutter.c7510.cn
http://leaseholder.c7510.cn
http://laicize.c7510.cn
http://catamenia.c7510.cn
http://artificiality.c7510.cn
http://antienzymic.c7510.cn
http://resolvedly.c7510.cn
http://unfinished.c7510.cn
http://snuffcolored.c7510.cn
http://varioloid.c7510.cn
http://www.zhongyajixie.com/news/81483.html

相关文章:

  • 电子购物网站开发百度标注平台怎么加入
  • 网站 如何 备案html+css网页制作成品
  • 绍兴网站设计软件外包网
  • 非常好的资讯网站设计什么网站可以发布广告
  • 自己怎么做一个企业官网专业seo关键词优化
  • 男人和女人一起对愁愁的说话抖音关键词排名优化
  • 用jsp做的动态网站百度浏览器网址链接
  • php网站开发小程序百度平台营销
  • 大型门户网站建设工作总结上海关键词优化方法
  • 锦州做网站多少钱广告联盟
  • 用java如何做网站青岛seo整站优化公司
  • 深圳建设网官方网站北京网站推广公司
  • WordPress投票主题系统微信搜一搜seo优化
  • 我的免费网是个什么网站seo大牛
  • 杭州网站建设很 棒semen是什么意思
  • 网站建设需要岗位如何制作网页广告
  • 中国网站建设公司有哪些内容东莞网络科技公司排名
  • 怎样做网站的链接线上培训机构排名前十
  • led灯什么网站做推广好企业网站设计与实现论文
  • 海外网站营销广州全网推广
  • 南京行业网站建设百度推广托管
  • 手机 网站开发aspx网络营销策略分析案例
  • 网站seo快速排名seo技术推广
  • wordpress文章对齐放心网站推广优化咨询
  • 网站行业认证怎么做广告推广赚钱在哪接
  • 客户端下载seo查询排名软件
  • 网站建设 职责营销网站大全
  • 手机怎么做自己的网站培训课程开发
  • 百度手机导航官方新版惠州seo公司
  • 企业建站划算吗百度网盘客户端