기술 자료

Unity Engine

Unity Engine

Linecast

Returns true if there is any collider intersecting the line between start and end.
읽는 시간 1분최근 업데이트: 한 달 전

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule

Linecast(Vector3, Vector3, int, QueryTriggerInteraction)

Returns true if there is any collider intersecting the line between
start
and
end
.
public static bool Linecast(Vector3 start, Vector3 end, int layerMask, QueryTriggerInteraction queryTriggerInteraction)

Parameters

start

Start point.

End point.

layerMask

A Layer mask that is used to selectively filter which colliders are considered when casting a ray.

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

bool

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public Transform target; void Update() { if (Physics.Linecast(transform.position, target.position)) { Debug.Log("blocked"); } }}

Linecast(Vector3, Vector3, RaycastHit, int, QueryTriggerInteraction)

Returns true if there is any collider intersecting the line between
start
and
end
.
public static bool Linecast(Vector3 start, Vector3 end, out RaycastHit hitInfo, int layerMask, QueryTriggerInteraction queryTriggerInteraction)

Parameters

start

Start point.

End point.

hitInfo

If true is returned,
hitInfo
will contain more information about where the collider was hit. (Additional Resources: RaycastHit).

layerMask

A Layer mask that is used to selectively filter which colliders are considered when casting a ray.

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

bool

Remarks

If true is returned,
hitInfo
will contain more information about where the collider was hit. (Additional Resources: RaycastHit). Layer mask is used to selectively ignore colliders when casting a ray.