using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
/*
 * Author:W
 * Lua代码中调用C#的API
 */
public class LuaUseCSCode : MonoBehaviour
{
    private LuaEnv luaEnv;
    // Start is called before the first frame update
    void Start()
    {
        luaEnv = new LuaEnv();

        //CS前缀+C#代码命名空间+C#类+C# API
        luaEnv.DoString("CS.UnityEngine.Debug.Log('Hello Lua!')");
    }

    private void OnDestroy()
    {
        if(luaEnv!=null)
          luaEnv.Dispose();
    }
}



运行结果截图如下
在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐