ドキュメント

Unity Engine

Unity Engine

IgnoreCollision(Collider, Collider, bool)

Makes the collision detection system ignore all collisions between collider1 and collider2.
読み終わるまでの所要時間 1 分最終更新 1ヶ月前

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule
public static void IgnoreCollision(Collider collider1, Collider collider2, bool ignore)

Parameters

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.

Remarks

This is useful, say, for preventing projectiles from colliding with the object that fires them.
Note that Physics.IgnoreCollision is not persistent. This means ignore collision state will not be stored in the editor when saving a scene.
If
ignore
is false, collisions can occur. Set
ignore
to true to ignore collisions.
Additional Resources: Physics.IgnoreLayerCollision.

Examples

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>()); }}