Search code examples
c#unity-game-enginetweenngui

Method Assignment to Tween Event with Different ways


Watch the below code snippet, it working fine (although method execution didn't test yet) and my method have assigned to tween onFinsih.

first line without EventDelgate and with EventDelegate? so what is the difference and efficient way to assign my custom methods to tween events.

using UnityEngine;
using System.Collections;

public class TweenEventMethodAssigner : MonoBehaviour {

    // Use this for initialization
    void Start () {
        gameObject.GetComponent<TweenPosition>().AddOnFinished(myOnFinish);
        gameObject.GetComponent<TweenPosition>().AddOnFinished(new EventDelegate(myOnFinish2));
    }

    // Update is called once per frame
    void Update () {

    }

    void myOnFinish() {
        Debug.Log("myOwnFinsih");
    }

    void myOnFinish2() {
        Debug.Log("myOwnFinsih : 2");
    }
}

Solution

  • They both the same. Internally the second version is used while you use the first one. It is just a shorter way to write the same thing.