调用实例成员

CallMember.lua.txt

  1. local GameObject = CS.UnityEngine.GameObject
  2. local obj = GameObject.Find('GameObject')
  3. --访问成员属性
  4. local transform = obj.transform
  5. print(transform.position)
  6. --对成员属性进行赋值
  7. transform.position = CS.UnityEngine.Vector3(1,1,1)
  8. --调用成员方法
  9. local camera = CS.UnityEngine.Camera.main
  10. camera.transform:LookAt(transform)

CallMember.cs

  1. /*
  2. * created by shenjun
  3. */
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using XLua;
  8. namespace shenjun
  9. {
  10. public class CallMember : MonoBehaviour {
  11. LuaEnv luaEnv = new LuaEnv();
  12. void Start () {
  13. luaEnv.DoString("require 'CallMember'");
  14. }
  15. void Update () {
  16. if(luaEnv != null)
  17. {
  18. luaEnv.Tick();
  19. }
  20. }
  21. private void OnDestroy()
  22. {
  23. luaEnv.Dispose();
  24. }
  25. }
  26. }

?