Action的使用

using UnityEngine;
using System.Collections;
using System;
public class Test : MonoBehaviour
{
    private Action callback;
    // Use this for initialization
    void Start ()
    {
        SetDestination(Vector2.one, delegate(string value)
        {
           //此处代码当Action调用的时候才会执行
            Debug.Log(value);
        });
    }
    // Update is called once per frame
    void Update ()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            callback(DateTime.Now.ToString());
        }
    }
    public void SetDestination(Vector2 point, Action callback)
    {
        Debug.Log(point);
        this.callback = callback;
    }
}

你可能感兴趣的:(Action的使用)