Unity-layermask的问题

 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)