I was working on a simple script that would toggle the active state of some objects using an UnityEvent based on a button press (I was planning on using this to stop a user from walking when opening a menu). The problem was that when I tried to select my extension method that I wrote for the GameObject class, it was nowhere to be found in the UnityEvent method selection dropdown. I have since realised that this solution was not really gonna work how I wanted it to, plus it was kind of ugly, but it still got me wondering: Is it possible to execute extension methods with UnityEvents?
Toggle script:
using UnityEngine;
public static class ExtensionMethods
{
public static void ToggleActive(this GameObject go)
{
go.SetActive(go.activeSelf);
}
}