【问题标题】:How to make my Roblox clickable block stop moviing如何让我的 Roblox 可点击块停止移动
【发布时间】:2021-09-02 21:06:00
【问题描述】:

我制作了一个带有脚本的块,当点击时它会移动

part = script.Parent

function move()
    part.Position = part.Position + Vector3.new(3,0,0)
    wait(1/30) -- Delay
    if part.Position.X > 45 then -
      part.Position = part.Position - Vector3.new(5,5,5)
      wait(1/30) -- 
    end
end

part.ClickDetector.MouseClick:connect(move)

这个方块无论如何都会穿过其他物体,我只需要想办法让它在一定距离后无法点击。

【问题讨论】:

标签: lua roblox


【解决方案1】:

这个块无论如何都会穿过其他物体,而我只是 需要想办法让它在一定距离后无法点击

您的代码每次点击都会将块移动一定距离。

点击时检查你的方块位置。如果新位置超出可点击范围,断开事件监听器。

另请注意,connect 已弃用。你应该使用Connect。请阅读 Roblox 手册。

https://developer.roblox.com/en-us/articles/events#disconnecting-a-function

local points = Instance.new("NumberValue")
points.Name = "Points"
points.Value = 0
 
local connection
 
local function onPointsChanged(newPoints)
  print("Points: " .. newPoints)
  if newPoints >= 50 then
      -- Stop listening for changes if we have at least 50 points
      connection:Disconnect()
  end
end
 
connection = points.Changed:Connect(onPointsChanged)
 
-- Trigger some changes
points.Value = 25
points.Value = 100
points.Value = 0  -- Prints nothing because we called Disconnect()

【讨论】:

    【解决方案2】:

    这个块无论如何都会穿过其他物体

    你的意思是它不会与物体发生碰撞?就像如果有一堵墙挡住了它,它无论如何都会穿过?如果是这样,也许你应该让它补间并在它检测到碰撞时停止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-03
      • 2013-09-02
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多