码迷,mamicode.com
首页 > 编程语言 > 详细

Unity-layermask的问题

时间:2015-04-28 13:34:13      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class NewBehaviourScript : MonoBehaviour {
 5     private RaycastHit info;
 6     LayerMask M1 = 1<<8;
 7     LayerMask M2 = 9<<10;
 8     // Use this for initialization
 9     void Start () {
10         if (Physics.Raycast(this.transform.position, new Vector3(0, 0, 1), out info,M1))
11         {
12             
13             print(info.collider.gameObject.name); }
14     }
15     
16     // Update is called once per frame
17     void Update () {
18         Debug.DrawLine(transform.position, info.point, Color.red);
19     }

之前就是这样写,但是发现不是m1的碰撞体还是被检测到了,今天 终于发现问题了

不知道是不是bug,就是 如果你不加distance的话 后面的mask unity是无视的

改成这样

(Physics.Raycast(this.transform.position, new Vector3(0, 0, 1), out info, Mathf.Infinity, M1))

就正常了。

Unity-layermask的问题

标签:

原文地址:http://www.cnblogs.com/mukeyang/p/4462563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!