MD Package Technical & APi Documentation
MDM_RaycastEvent
Namespace: MDPackage.Modifiers
Simple raycast behaviour with customizable events.
Read more here (Online documentation slide)
Public Methods
// Update current Raycast (if 'Update Ray Per Frame' is disabled)
public void RayEvent_UpdateRaycastState()
Public Fields and Properties
public bool updateRayPerFrame = true;
public bool usesPhysics = false;

public float rayLength = 5.0f;
public bool pointRay = true; // Is this a spherical ray or pointy ray?
public float sphericalRadius = 0.2f;
public bool localRay = true; // Local/worldspace
public Vector3 globalRayDir = new Vector3(0, -1, 0);

public LayerMask rayLayer = ~0;
public bool raycastWithSpecificTag = false;
public string raycastTag = "";

public UnityEvent eventOnRaycast;
public UnityEvent eventOnRaycastExit;
public event Action eventActionOnRaycast;
public event Action eventActionOnRaycastExit;

public RaycastHit[] RayEventHits { get; }
public Ray RayEventRay { get; }
Examples
The following paragraphs contain RaycastEvent modifier used in a practical example. Subscription to RaycastEvent events.
using UnityEngine;
using MDPackage.Modifiers;

// Sample script for RaycastEvent modifier - subscribe to raycastEvent events - apply this script to any Unity gameObject and properly assign empty fields
public class SampleScript : MonoBehaviour
{
// Assign an already existing rayevent
public MDM_RaycastEvent targetRayEvent;

private void OnEnable()
 {
  // Subscribe to an event
  if (targetRayEvent)
   targetRayEvent.eventActionOnRaycast += IsCasting;
 }

private void OnDisable()
 {
  // Unsubscribe to an event
  if (targetRayEvent)
   targetRayEvent.eventActionOnRaycast -= IsCasting;
 }

private void Update()
 {
  // Check every frame
  if (targetRayEvent && targetRayEvent.RayEvent_IsRaycasting())
   Debug.Log("Is casting in update!");
 }

private void IsCasting()
 {
  Debug.Log("Is casting event!");
 }
}