lua - 在 Lua 中被玩家踩到时减小对象大小
问题描述
我想知道如何在 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)
解决方案
Size.Y 指的是 NumberValue,您正在尝试与向量进行比较和相加。
local snowPart = game.Workspace.Snow.SnowPart -- part I want to change
while snowPart.Size.Y <= 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 - Vector3.new(0, 0.7, 0) --increment the part's size when touched by a player
end
end
snowPart.Touched:Connect(onTouch)
您可能想看看使用 lerp 并使过渡更平滑。此外,可能值得查看 wiki 的功能。http://wiki.roblox.com
推荐阅读
- java - 我应该如何创建 Java 应用程序,我应该在哪里放置类?
- javascript - 如何从另一个组件单击按钮时更新一个类组件中的状态?
- android - 函数从不用于 LifecycleObserver 中使用 OnLifecycleEvent 注释的方法
- mysql - 我在mysql中过滤日期时间有问题
- bash - 外壳内的heredoc有问题。bash 脚本
- java - 铸件供应商
给供应商 爪哇 - r - 如何找到投资组合中每只股票的月收益
- c# - 如何避免 Linq 中过滤器 API 中的 if else 语句
- html - 透明导航栏 - 不显示背景
- android - 境界+魔石| @JsonClass 不能应用于 [class],RealmObject 不是 Kotlin 类型public