如何在单击按钮时制作补间模型

问题描述 投票:0回答:1

我的模型层次结构如下所示:

1. Core
2. Union
2. (Other parts I want to tween with the door)
2. Button
3. (Inside the button) Click detector
3. (Inside the button) Local script

图像更容易阅读 enter image description here

local button = script.Parent
local parentPart = button.Parent -- Assuming the parent part contains all the parts you want to move together

local startPosition = parentPart.Position -- Set the starting position of the parent part
local endPosition = Vector3.new(0, 5, 0)  -- Replace with the desired end position

local TweenService = game:GetService("TweenService")

local function onButtonClicked()
    local tweenInfo = TweenInfo.new(
        2,             -- Duration of the tween in seconds
        Enum.EasingStyle.Quad, -- Easing style (you can change this to other styles)
        Enum.EasingDirection.Out
    )
    local tween = TweenService:Create(parentPart, tweenInfo, {Position = endPosition})
    tween:Play()
end

button.MouseClick:Connect(onButtonClicked)

我使用了之前的代码并单击了按钮。我预计模型会向上移动,到达我指定的点。

我点击了它,但什么也没发生

animation lua roblox tween
1个回答
0
投票

您的按钮部分是否包含点击检测器?

local clickDetector = script.Parent.ClickDetector
local parentPart = script.Parent

local tweenService = game:GetService('TweenService')

clickDetector.MouseClick:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        local tween = tweenService:Create(parentPart, TweenInfo.new(), {Position = Vector3.new(0,5,0)})
        tween:Play()
    end
end)
© www.soinside.com 2019 - 2024. All rights reserved.