I wish to expose a script’s function
to the inspector, but I have no clue how to.
I found [this][1] here, which was a start, but it isn’t clear how to finish.
My code for the class:
[System.Serializable]
class MoveAction : UnityEvent<MonoBehaviour>, IUIAnimationEvent
{
#region Move
public MoveAction()
{
}
//to ensure only one mover coroutine can be active.
IEnumerator moveRoutine = null;
#region Solution 2: using fields and not parameters
Transform from;
Transform to;
float overTime;
public delegate void UIchain(MonoBehaviour mono);
public event UIchain NEXT_FUNCTION;
public MoveAction(Transform from, Transform to, float overTime, IUIAnimationEvent chain)
{
this.from = from;
this.to = to;
this.overTime = overTime;
}
public void Move(MonoBehaviour mono)
{
if (moveRoutine != null)
{
mono.StopCoroutine(moveRoutine);
}
moveRoutine = _Move(from, to, overTime, mono);
mono.StartCoroutine(moveRoutine);
Invoke(mono);
}
IEnumerator _Move(Transform from, Transform to, float overTime, MonoBehaviour mono)
{
Vector2 original = from.position;
float timer = 0.0f;
while (timer < overTime)
{
float step = Vector2.Distance(original, to.position) * (Time.deltaTime / overTime);
from.position = Vector2.MoveTowards(from.position, to.position, step);
timer += Time.deltaTime;
yield return null;
}
if(NEXT_FUNCTION != null)
{
NEXT_FUNCTION(mono);
}
}
This is a lot of code, but the interesting part is the Move(MonoBehaviour mono)
function.
I want to expose that to the editor. How?
[1]: Select monobehaviour function from inspector - Questions & Answers - Unity Discussions