Does anyone know how to do this in javascript? I am using Unity 4.6 and no I can’t upgrade to 5.
Basically this is what I have, and I don’t get errors, but my function doesn’t fire. The entry does get added at runtime since I see the Select event in the inspector. However, the function doesn’t appear in the inspector. I tried this using c# and works, but that doesn’t appear in the inspector either. I don’t care if it appears or not in the inspector, I just want the function to fire.
function Start ()
{
var trigger : EventTrigger = gameObject.GetComponent (EventTrigger);
var entry : EventTrigger.Entry = EventTrigger.Entry();
entry.eventID = EventTriggerType.Select;
entry.callback = EventTrigger.TriggerEvent ();
var l_callback : UnityEngine.Events.UnityAction.<UnityEventBase> = UnityEngine.Events.UnityAction.<UnityEventBase>(OnSelectOption);
entry.callback.AddListener(function (){l_callback;});
trigger.delegates.Add (entry);
}
public function OnSelectOption (baseEvent:UnityEventBase)
{
Debug.Log ("Hello World");
}
I believe “entry.callback.AddListener(function (){l_callback;});” is not correct and l_callback is not assigned as a listener. So the syntax for this line is what I am having an issue with. I usually code in c#, but due to the project I am working on being all in javascript, it has to be in javascript (e.g) first pass methodology won’t work since I need cross communication between scripts and assets.