【Unity】XLua访问C#文件

创建NPC.cs:

public class NPC

{

public string name;

public int age;

public void Say()

{

Debug.Log("Say:我是未被修改的");

}

public static void Say()

{

Debug.Log("Static Say:我是未被修改的");

}

public void Say2(int a)

{

Debug.Log(a);

}

public static NPC CreateNPC(string name_, int age_)

{

NPC npc = new NPC();

npc.name = name_;

npc.age = age_;

return npc;

}

}

(1)lua文件访问类的普通方法(需通过C#文件调用):

npc = CS.NPC()

npc.name = "zhaoxi"

npc.age = 10

npc:Say()

npc:Say2(2)

(2)lua文件访问类的静态方法(需通过C#文件调用):

npc2 = CS.NPC.CreateNPC("zhaoxi", 23)

npc2:Say()

(3)lua文件在场景创建一个物体

go = CS.UnityEngine.GameObject()

go.name = "新游戏物体"

你可能感兴趣的:(Unity,Unity,Lua,C#,游戏引擎,游戏开发)