调用静态成员

CallStatic.lua.txt

  1. --访问静态属性
  2. local deltaTime = CS.UnityEngine.Time.deltaTime - CS.UnityEngine.Time.deltaTime%0.001
  3. print("Time deltaTime :", deltaTime)
  4. --对静态属性进行赋值
  5. CS.UnityEngine.Time.timeScale = 0.5
  6. print("Time timeScale :", CS.UnityEngine.Time.timeScale)
  7. --调用静态方法
  8. local GameObject = CS.UnityEngine.GameObject
  9. local obj = GameObject.Find('GameObject')
  10. if nil ~= obj then
  11. print("Destroy GameObject")
  12. CS.UnityEngine.Object.Destroy(obj)
  13. end

CallStatic.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 CallStatic : MonoBehaviour {
  11. void Start () {
  12. LuaEnv luaEnv = new LuaEnv();
  13. luaEnv.DoString("require 'CallStatic'");
  14. luaEnv.Dispose();
  15. }
  16. }
  17. }

?