当前位置: 首页>>代码示例>>C#>>正文


C# CircleCollider2D.GetComponent方法代码示例

本文整理汇总了C#中UnityEngine.CircleCollider2D.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# CircleCollider2D.GetComponent方法的具体用法?C# CircleCollider2D.GetComponent怎么用?C# CircleCollider2D.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.CircleCollider2D的用法示例。


在下文中一共展示了CircleCollider2D.GetComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BodyCollide

    //TODO make multi-path colliders work......
    /// <summary>
    /// Generates the fine details between two known-colliding Collider2D objects.
    /// One collider will be a CircleCollider2D and the other will be a PolygonCollider2D that belongs to a JelloBody.
    /// </summary>
    /// <param name="collA">The CircleCollider2D involved in the collision.</param>
    /// <param name="info">The SupplementartyColliderInfo representing the PolygonCollider2D that belongs to a JelloBody involved in the collision.</param>
    /// <param name="contacts">The JelloContact list to add any generated JelloContact to.</param>
    public void BodyCollide(CircleCollider2D collA, SupplementaryColliderInfo info, ref List<JelloContact> contacts)
    {
        JelloContact contact;
        Vector2 pt;
        Vector2 hitPt;
        Vector2 norm;
        float scalarAB;
        float dist;
        float radius;

        //contact = new JelloContact();
        radius = collA.radius * Mathf.Max(collA.transform.localScale.x, collA.transform.localScale.y);

        pt = (Vector2)collA.transform.TransformPoint(collA.offset);

        //for each pointmass in body B
        for (int j = 0; j < info.ColliderVertices.Length - 2; j++)
        {
            //get collision info
            dist = JelloVectorTools.getClosestPointOnSegmentSquared(pt, info.ColliderVertices[j + 1], info.ColliderVertices[j + 2], out hitPt, out norm, out scalarAB); //TODO make this work with fully penetrated circles.
            //fill out collisioninfo
            if(dist < radius * radius)
            {
                contact = new JelloContact();

                contact.bodyA = null;
                contact.colliderA = collA;
                contact.rigidbodyA = collA.GetComponent<Rigidbody2D>();
                contact.transformA = collA.transform;
                contact.bodyB = info.body;
                contact.colliderB = info.collider;
                contact.rigidbodyB = info.collider.GetComponent<Rigidbody2D>();
                contact.transformB = info.collider.transform;
                contact.bodyBpmA = j;
                contact.bodyBpmB = j + 1 > info.ColliderVertices.Length - 3 ? 0 : j + 1;
                contact.scalarAB = scalarAB;
                contact.hitPoint = hitPt;
                contact.normal = (hitPt - pt).normalized * (JelloShapeTools.Contains(info.ColliderVertices, pt) ? 1f : -1f);
                contact.mtv = contact.normal;
                contact.penetration = radius - Mathf.Sqrt(dist);
                contact.R = contact.hitPoint - (Vector2)collA.transform.position;
                contact.R2 = contact.hitPoint - (Vector2)info.collider.transform.position;

                contacts.Add(contact);
            }
        }
    }
开发者ID:tmkebr,项目名称:TriangleEater,代码行数:55,代码来源:JelloWorld.cs


注:本文中的UnityEngine.CircleCollider2D.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。