Version: 2017.2

Physics.IgnoreCollision

切换到手册
public static void IgnoreCollision (Collider collider1, Collider collider2, bool ignore= true);

参数

start 起点。
end 终点。
ignore 忽略碰撞。

描述

使碰撞检测系统忽略 collider1collider2 之间的所有碰撞。

这在某些情况下很有用。 例如,防止飞弹与发射飞弹的对象发生碰撞。

IgnoreCollision 有一些限制: 1) It is not persistent. This means ignore collision state will not be stored in the editor when saving a scene. 2) 您只能将忽略碰撞应用于活动游戏对象中的碰撞体。

另请参阅:Physics.IgnoreLayerCollision

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>()); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961