You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LuaException: [string "Cube (1)"]:7: attempt to call a nil value (method 'Translate')
stack traceback:
[string "Cube (1)"]:7: in function <[string "Cube (1)"]:5>
at XLua.LuaEnv.ThrowExceptionFromError (System.Int32 oldTop) [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
### lua: 保存一个lua文件
`UnityEngine =CS.UnityEngine
speed = 3
movingRight=true
function Update()
if movingRight then
transform:Translate(UnityEngine.Vector3.right * speed * UnityEngine.Time.deltaTime)
if transform.position.x >= 5 then
movingRight = false
end
else
transform:Translate(UnityEngine.Vector3.left * speed * UnityEngine.Time.deltaTime)
if transform.position.x <= -5 then
movingRight = true;
end
end
end`
c#
` using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
public class dome1 : MonoBehaviour
{
private XLua.LuaEnv luaenv;
public TextAsset luaTxt;// 依赖上方lua文件
private LuaTable _self;
void Start()
{
//实例化虚拟机
luaenv = new XLua.LuaEnv();
//创建表和元表
_self = luaenv.NewTable();
LuaTable meta = luaenv.NewTable();
meta.Set("__index", luaenv.Global);
_self.SetMetaTable(meta);
meta.Dispose();
_self.Set("self", this);
_self.Set("transform", transform);
luaenv.DoString(luaTxt.text, transform.name, _self);
_self.Get("Update", out onUpdate);
}
private void OnDestroy()
{
onUpdate = null;
luaenv.Dispose();
}
private Action onUpdate;
// Update is called once per frame
void Update()
{
if (onUpdate != null)
{
onUpdate.Invoke();
}
}
}`
The text was updated successfully, but these errors were encountered:
unity2019.4.24f1c1
xlua 2022.4.20 下载的版本(最新)
lua中调用transform:Translate,编辑器、windows(打包后exe)工作正常
webgl 出现错误
LuaException: [string "Cube (1)"]:7: attempt to call a nil value (method 'Translate')
stack traceback:
[string "Cube (1)"]:7: in function <[string "Cube (1)"]:5>
at XLua.LuaEnv.ThrowExceptionFromError (System.Int32 oldTop) [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
### lua: 保存一个lua文件
`UnityEngine =CS.UnityEngine
speed = 3
movingRight=true
function Update()
if movingRight then
transform:Translate(UnityEngine.Vector3.right * speed * UnityEngine.Time.deltaTime)
if transform.position.x >= 5 then
movingRight = false
end
else
transform:Translate(UnityEngine.Vector3.left * speed * UnityEngine.Time.deltaTime)
if transform.position.x <= -5 then
movingRight = true;
end
end
end`
c#
` using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
public class dome1 : MonoBehaviour
{
private XLua.LuaEnv luaenv;
public TextAsset luaTxt;// 依赖上方lua文件
private LuaTable _self;
}`
The text was updated successfully, but these errors were encountered: