【发布时间】:2016-06-05 21:08:15
【问题描述】:
这是 Lua 代码。我想发送 XXPos、YYPos、ZZPos。但是在unity3d中,它只接收XXPos。
socket = require("socket")
print(socket._VERSION)
function dataListener:post( t )
local XPos = ship.rb:getPosition():x()
local YPos = ship.rb:getPosition():y()
local ZPos = ship.rb:getPosition():z()
local XXPos = math.floor( XPos * 1000 + 0.5 ) / 1000
local YYPos = math.floor( YPos * 1000 + 0.5 ) / 1000
local ZZPos = math.floor( ZPos * 1000 + 0.5 ) / 1000
udp=socket.udp();
udp:setpeername("127.0.0.1",8051)
udp:send(XXPos, " ", YYPos, " ", ZZPos);
end
当我像这样更改 Lua 代码时,
--udp:send(XXPos, " ", YYPos, " ", ZZPos)
udp:send(string.format("%d; %d; %d",XXPos,YYPos,ZZPos))
数据被正确接收。但是这个结果有 1 个数字,比如 3; 5个; 2.
如何更改此 Lua 代码?
【问题讨论】:
-
“这个结果有 1 个数字,比如 3; 5; 2。”是什么意思?除此之外,似乎 udp:send() 只接受一个参数,所以你必须组装字符串。 string.format 是要走的路。
-
我想要一只彩虹独角兽。
-
你期望成为什么样的人?
-
@JeroenvanLangen XXPos 结果为 0.xxx 。所以,我想要 0.xxx; x.xxx; x.xxx
-
@JimanAn 看看我的回答。这可能就是您要寻找的。span>