- Home /
NGUI: Set OnFinished Callback Causes Compile Error
Hello
I am getting a compiler error when I try to specify my own custom on finished method. The OnFinished
method will execute when a NGUI::TweenScale
has completed?
The compile error is:
}Operator
+=' cannot be applied to operands of type
System.Collections.Generic.List' andmethod group' **Why is this happening and how can I fix it?** Note I've posted on the [NGUI forums][1] but no responses after 1.5 days. using UnityEngine; using System.Collections; public class CircularMenu : MonoBehaviour { private void OnEnable() { GetComponent<TweenScale>().onFinished += onScaleFinished; // Compile error: Operator
+=' cannot be applied to operands of typeSystem.Collections.Generic.List<EventDelegate>' and
method group'
private void OnDisable() {
GetComponent().onFinished -= onScaleFinished; } private void onScaleFinished(GameObject go) { } } [1]: http://www.tasharen.com/forum/index.php?topic=10404.0
Answer by rutter · Jul 17, 2014 at 12:15 AM
Because onFinished
has a type of List
(see NGUI docs). That collection doesn't have a defined +=
operator.
You may instead want to call AddOnFinished:
GetComponent<TweenScale>().AddOnFinished(onScaleFinished);
If you want to also call RemoveOnFinished, you may need to read up on constructing an EventDelegate, which NGUI uses internally to create a sort of serializable callback reference.
My thought is that there's probably an easier way to manage this. Don't forget that you can write your own custom component that manages some of this internally.
Your answer
Follow this Question
Related Questions
NGUI UICenterOnChild, find out what is centered 1 Answer
Sequential disabling of menu 0 Answers
Ngui Scaling Issues With popuplist 0 Answers
Setting Background using NGUI 0 Answers