返回介绍

Physics2D.IgnoreCollision 忽略碰撞

发布于 2019-12-18 15:38:17 字数 3390 浏览 1057 评论 0 收藏 0

JavaScript => static function IgnoreCollision(collider1: Collider2D, collider2: Collider2D, ignore: bool = true): void;
C# => static void IgnoreCollision(Collider2D collider1, Collider2D collider2, bool ignore = true);

Parameters 参数

collider1The first collider to compare to collider2.
第一个碰撞器与collider2比较。
collider2The second collider to compare to collider1.
第二个碰撞器与collider1比较。
ignoreWhether collisions/triggers between collider1 and collider2 should be ignored or not.
collider1collider2之间的碰撞/触发是否应该被忽略。

Description 描述

Makes the collision detection system ignore all collisions/triggers between collider1 and collider2.
使碰撞检测系统忽略collider1和collider2之间的所有碰撞/触发。

Ignoring collisions refers to any type of interaction between the selected colliders i.e. no collision or trigger interaction will occur. Collision layers are first checked to see the two layers can interact and if not then no interactions take place. Following that, ignoring specific colliders interactions will occur.
忽略碰撞是指被选中的碰撞器之间的所有交互,也就是不会发生碰撞或触发交互。碰撞层首先检测两个图层会不会相互作用,如果不那么就不会发生相互作用。接着,忽略特定碰撞器之间的相互交互将发生。

IgnoreCollision has a few limitations: 1) It is not persistent. This means that the ignore collision state will not be stored in the editor when saving a scene. 2) You can only apply the ignore collision to colliders in active game objects. When deactivating the collider the IgnoreCollision state will be lost and you have to call Physics2D.IgnoreCollision again. See Also: Physics2D.GetIgnoreCollision, Physics2D.IgnoreLayerCollision.
IgnoreCollision有一些局限性:1) 它不是持久的。这意味着保存场景时不保存忽略碰撞的状态。2) 只能在激活的游戏对象物体上应用。当使碰撞器被取消激活时,忽略碰撞的状态将消失,必须要再调用一次Physics2D.IgnoreCollision. See Also: Physics2D.GetIgnoreCollision, Physics2D.IgnoreLayerCollision.

JavaScript:

	// Instantiate a bullet and make it ignore collisions with this object.\\ 
	// 实例化一个子弹然后使他与当前物体之间忽略碰撞。
	var bulletPrefab : Transform;
	function Start () {
		var bullet = Instantiate(bulletPrefab) as Transform;
		Physics2D.IgnoreCollision(bullet.collider2D, collider2D);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Transform bulletPrefab;
    void Start() {
        Transform bullet = Instantiate(bulletPrefab) as Transform;
        Physics2D.IgnoreCollision(bullet.collider2D, collider2D);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文