Menu
CoddyTech

手电筒

Coddy Roblox 游戏:逃离黑暗 课程的第 2 课,共 25 课。

在黑暗中,你需要一支手电筒。它是 ServerStorage 中的一个 Tool,它的 Handle 上有一个名为 Beam 的 SpotLight:它会从部件的一面,也就是手电筒的前端,射出锥形光束。

玩家每次生成时,Backpack 都会被清空,所以每次触发 CharacterAdded 时都会发放手电筒。手持工具时点击会触发它的 Activated 事件,服务器端也是如此,然后光束就会切换状态:

flashlight.Activated:Connect(function()
	beam.Enabled = not beam.Enabled
end)

按 1 拿起手电筒,然后点击将它打开。

challenge icon

挑战

简单

给每位玩家一个可以开关的手电筒。

  1. 在 Players.PlayerAdded 中,每当触发 player.CharacterAdded 时,就将 ServerStorage.Flashlight 克隆到 player.Backpack 中。
  2. 连接手电筒的 Activated,用来切换 Handle.Beam.Enabled。

按“开始”,按 1 并点击:一道光束划破黑暗。然后按“检查”。

亲手试试

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")
local Settings = require(game.ReplicatedStorage.Settings)

-- 夜幕降临:没有阳光,到处有一点微光,还起了雾。
Lighting.ClockTime = Settings.ClockTime
Lighting.Ambient = Settings.Ambient
Lighting.OutdoorAmbient = Settings.Ambient
Lighting.FogColor = Color3.new(0, 0, 0)
Lighting.FogEnd = Settings.FogEnd
print("Lights out")

-- 第 2 课:在这里添加 Flashlight

Roblox 游戏:逃离黑暗中的所有课

自己练习: Roblox 在线编辑器