【发布时间】:2019-10-04 23:46:00
【问题描述】:
我想知道如何在 Lua 中逐渐增加对象的大小(每次玩家踩到该对象或执行操作时)。 我的代码如下:
local snowPart = game.Workspace.Snow.SnowPart -- part I want to change
while snowPart.Size.Y == Vector3.new(0, 0, 0) do
wait(10)
snowPart.Size.Y = snowPart.Size + Vector3.new(0, 0.7, 0) --increment if the part gets too small
end
function onTouch(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
wait(5)
snowPart.Size = snowPart.Size.Y - Vector3.new(0, 0.7, 0) --increment the part's size when touched by a player
end
end
snowPart.Touched:Connect(onTouch)
【问题讨论】:
-
据我所见,如果
snowPart.Size.Y为 (0, 0, 0),则您当前正在强制snowPart.Size.Y为 (0, 0.7, 0),如果有人踩到snowPart,您根据此将大小减小 (0, 0.7, 0)。但是,while 循环的下一次迭代会将大小重置为 (0, 0.7, 0)。你的预期行为是什么? [注意:我不知道 Size 和 Size.Y 在这种情况下是如何工作的,也不知道为什么 Size.Y 是 Vector3 而不是简单的 double]