求教关于射线的问题,如何让射线只与某层上的物件碰撞
答案:1 悬赏:20 手机版
解决时间 2021-03-29 22:18
- 提问者网友:山高云阔
- 2021-03-29 07:39
求教关于射线的问题,如何让射线只与某层上的物件碰撞
最佳答案
- 五星知识达人网友:荒野風
- 2021-03-29 08:06
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");
}
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯