Linecast
Returns true if there is any collider intersecting the line between start and end.
Read time 1 minuteLast updated 4 days ago
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 point.
End point.
A Layer mask that is used to selectively filter which colliders are considered when casting a ray.
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 point.
End point.
If true is returned, hitInfo will contain more information about where the collider was hit. (Additional Resources: RaycastHit).
A Layer mask that is used to selectively filter which colliders are considered when casting a ray.
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.