求教关于射线的问题,如何让射线只与某层上的物件碰撞
展开全部
c#:
using UnityEngine;
using System.Collections;
public class Pathing : MonoBehaviour {
private int LayerGround;
private bool CastRays = true;
void Start () {
LayerGround = LayerMask.NameToLayer("Ground");
}
void Update () {
if (CastRays) {
Ray ray = Camera.mainCamera.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
// Raycast
if (Physics.Raycast(ray, out hit, Mathf.Infinity)) {
if (hit.transform.gameObject.layer == LayerGround) {
Debug.Log("Ground");//这里和指定层碰撞
} else {
Debug.Log("Other Objects");
}
}
}
}
}
js:
private var LayerGround;
private var CastRays : boolean = true;
function Start () {
LayerGround = LayerMask.NameToLayer("Ground");
}
function Update () {
if (CastRays) {
var ray = Camera.mainCamera.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
// Raycast
if (Physics.Raycast(ray, hit, Mathf.Infinity)) {
if (hit.transform.gameObject.layer == LayerGround) {
Debug.Log("Ground");//这里和指定层碰撞
} else {
Debug.Log("Other Objects");
}
}
}
}
using UnityEngine;
using System.Collections;
public class Pathing : MonoBehaviour {
private int LayerGround;
private bool CastRays = true;
void Start () {
LayerGround = LayerMask.NameToLayer("Ground");
}
void Update () {
if (CastRays) {
Ray ray = Camera.mainCamera.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
// Raycast
if (Physics.Raycast(ray, out hit, Mathf.Infinity)) {
if (hit.transform.gameObject.layer == LayerGround) {
Debug.Log("Ground");//这里和指定层碰撞
} else {
Debug.Log("Other Objects");
}
}
}
}
}
js:
private var LayerGround;
private var CastRays : boolean = true;
function Start () {
LayerGround = LayerMask.NameToLayer("Ground");
}
function Update () {
if (CastRays) {
var ray = Camera.mainCamera.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
// Raycast
if (Physics.Raycast(ray, hit, Mathf.Infinity)) {
if (hit.transform.gameObject.layer == LayerGround) {
Debug.Log("Ground");//这里和指定层碰撞
} else {
Debug.Log("Other Objects");
}
}
}
}
三英精密仪器有限公司
2023-08-25 广告
2023-08-25 广告
射线检测是一种无损检测方法,它利用射线的穿透性和成像能力来检测物体内部的缺陷和异常。天津三英精密仪器股份有限公司的射线检测设备采用先进的数字化技术,可以将检测结果以图像的形式呈现,方便用户快速准确地判断物体内部的缺陷和异常。该设备适用于各种...
点击进入详情页
本回答由三英精密仪器有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询