解决指定物体不发生碰撞

指定不碰撞的方法有层设置,触发器,前面单机版比较实用,但在网络游戏中某些场合不适用,比如自己的技能打出去不能伤害自己,同一个英雄可能好几个玩家都在用,设置层碰撞明显不好解决,用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>());
}

}

发布了49 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_23158477/article/details/102667626