IgnoreCollision(Collider, Collider, bool)
Makes the collision detection system ignore all collisions between collider1 and collider2.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.PhysicsModule
public static void IgnoreCollision(Collider collider1, Collider collider2, bool ignore)
Parameters
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 is false, collisions can occur. Set to true to ignore collisions.
ignoreignoreAdditional 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>()); }}