指定不碰撞的方法有层设置,触发器,前面单机版比较实用,但在网络游戏中某些场合不适用,比如自己的技能打出去不能伤害自己,同一个英雄可能好几个玩家都在用,设置层碰撞明显不好解决,用unity官网 Physics.IgnoreCollision来解决,方法如下:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public Transform bulletPrefab;
void Start()
{
Transform bullet = Instantiate(bulletPrefab) as Transform;
Physics.IgnoreCollision(bullet.GetComponent<Collider>(), GetComponent<Collider>());
}
}