本文整理汇总了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>();
}