Skip to content

Instantly share code, notes, and snippets.

@ryanmillerca
Created May 18, 2020 16:18
Show Gist options
  • Save ryanmillerca/3d6177e8cd5cb09b1dbf2b7fc81787bf to your computer and use it in GitHub Desktop.
Save ryanmillerca/3d6177e8cd5cb09b1dbf2b7fc81787bf to your computer and use it in GitHub Desktop.
Event Ferry (to connect Animation Events to UnityEvents)
// Event Ferry
// used to fake UnityEvent support into Animation Clip events.
// place on the gameObject with the Animator component
// call TriggerEvent with the index of the event previously specified
// Made by Ryan Miller (https://www.ryanmiller.ca)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class EventFerry : MonoBehaviour {
/// <summary>
/// Hook these up in inspector to create the target of your unity events
/// </summary>
public UnityEvent[] outgoingEvents;
/// <summary>
/// Trigger this from AnimationEvents
/// </summary>
public void TriggerEvent(int index){
if (outgoingEvents.Length > index){
outgoingEvents[index].Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment