collider1 | Any collider. |
collider2 | Another collider you want to have collider1 to start or stop ignoring collisions with. |
ignore | Whether or not the collisions between the two colliders should be ignored or not. |
使碰撞检测系统忽略 collider1
与 collider2
之间的所有碰撞。
这在某些情况下很有用。
例如,防止飞弹与发射飞弹的对象发生碰撞。
Note that IgnoreCollision is not persitent. This means ignore collision state will not be stored in the editor when saving a scene.
另请参阅: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>()); } }