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


C# Waypoint.GetComponent方法代码示例

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


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

示例1: HaveLineOfSight

    /// <summary>
    /// Function to calculate if 2 waypoints have a line of sight to each other
    /// </summary>
    public static bool HaveLineOfSight(Waypoint w1, Waypoint w2, float lineOfSightWidth)
    {
        // Do not check against self
        if (w1 == w2)
        {
            return false;
        }

        // Do not check with nulls
        if (w1 == null || w2 == null)
        {
            return false;
        }

        // Store the enabled status of the collider
        bool colliderEnabled = false;
        Collider2D w1Collider = w1.GetComponent<Collider2D>();

        // Disable the origin object's collider so that the raycast dosesn't hit the origin object
        if (w1Collider != null)
        {
            // Save the collider state for restoration later
            colliderEnabled = w1Collider.enabled;
            // Disable the collider for ray casting
            w1Collider.enabled = false;
        }

        // Define the LayerMask for Circle Cast checking to only check Waypoint and Environment masks
        int layerMask = (1 << LayerMask.NameToLayer("Waypoint")) | (1 << LayerMask.NameToLayer("Environment"));

        // Circle Cast check for Line of Sight
        RaycastHit2D castInfo = Physics2D.CircleCast(w1.transform.position, lineOfSightWidth, GetDirection(w1, w2), NEIGHBOURING_DIST, layerMask);

        // Reset the origin object's collider back to original
        if (w1Collider)
        {
            w1Collider.enabled = colliderEnabled;
        }

        // If we are able to collide with w2, means we have a straight line towards it
        return castInfo.collider == w2.GetComponent<Collider2D>();
    }
开发者ID:Pycorax,项目名称:SP4Unity,代码行数:45,代码来源:Waypoint.cs


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