Skip to content

Instantly share code, notes, and snippets.

@Problematic
Created November 14, 2016 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Problematic/aff719ed77a4416e49097faa3fd088d0 to your computer and use it in GitHub Desktop.
Save Problematic/aff719ed77a4416e49097faa3fd088d0 to your computer and use it in GitHub Desktop.
using UnityEngine;
[CreateAssetMenu]
public class CastService : ScriptableObject
{
public float maxDistance = Mathf.Infinity;
public LayerMask mask;
public QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal;
public bool Raycast (Vector3 origin, Vector3 direction, out RaycastHit hitInfo)
{
return Physics.Raycast (origin, direction, out hitInfo, maxDistance, mask.value, queryTriggerInteraction);
}
public bool BoxCast (Vector3 center, Vector3 halfExtents, Vector3 direction, out RaycastHit hitInfo, Quaternion orientation)
{
return Physics.BoxCast (center, halfExtents, direction, out hitInfo, orientation, maxDistance, mask.value, queryTriggerInteraction);
}
public bool BoxCast (Bounds bounds, Vector3 direction, out RaycastHit hitInfo, Quaternion orientation)
{
return BoxCast (bounds.center, bounds.extents / 2f, direction, out hitInfo, orientation);
}
public int OverlapSphereNonAlloc (Vector3 position, Collider[] results)
{
return Physics.OverlapSphereNonAlloc (position, maxDistance, results, mask.value, queryTriggerInteraction);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment