사라지는 발판
Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 18개 중 6번째.
Vanish 태그가 붙은 유리 발판은 밟고 나면 곧 사라졌다가 다시 나타납니다. CanCollide가 꺼진 파트는 통과할 수 있고, Transparency가 높으면 사라진 것처럼 보입니다:
part.Transparency = 0.8
part.CanCollide = false발판에 닿는 각 팔다리마다 Touched가 실행되고, 발판을 뚫고 떨어지는 동안에도 다시 실행됩니다. 확인 절차가 없으면 닿을 때마다 각자 페이드가 시작되어, 이미 지나간 뒤에도 발판이 깜박입니다. 디바운스를 사용하면 첫 번째 접촉만 처리할 수 있습니다. 발판이 처리 중일 때 표시를 해 두고, 표시가 있는 동안에는 접촉을 무시합니다.
if part:GetAttribute("Gone") then
return
end
part:SetAttribute("Gone", true)
-- 서서히 사라졌다가, 기다린 후, 다시 나타나기
part:SetAttribute("Gone", nil)기다리는 작업은 Touched 함수 안에서 이루어집니다. Roblox가 이 함수를 별도로 실행하므로 게임의 나머지 부분이 멈추지 않습니다.
챌린지
중급makeVanish(part)를 작성하고 setupStage에서 Vanish 태그가 지정된 모든 파트에 사용하세요. Humanoid가 있는 무언가가 발판에 닿았을 때 발판이 이미 사라진 상태가 아니라면:
- 속성
Gone을 true로 설정합니다. Settings.VanishDelay만큼 기다린 다음 Transparency를 0.8로, CanCollide를 false로 설정합니다.Settings.VanishTime만큼 기다린 다음 값을 각각 0과 true로 되돌리고Gone을 지웁니다(nil로 설정).
Play를 누르고 계속 움직이세요. 그런 다음 Check를 누르세요.
직접 해보기
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local Settings = require(game.ReplicatedStorage.Settings)
local stages = ServerStorage.Stages
local tower = nil
print("Each tower has " .. Settings.StageCount .. " stages")
-- 모든 플레이어의 리더보드에 Wins가 추가됩니다
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
end)
-- Kill 태그가 붙은 것에 닿으면 생명이 끝납니다
local function killOnTouch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- Spinners는 매 프레임 조금씩 회전합니다
RunService.Heartbeat:Connect(function(dt)
for _, spinner in CollectionService:GetTagged("Spinner") do
if spinner:IsDescendantOf(workspace) then
spinner:PivotTo(spinner:GetPivot() * CFrame.Angles(0, math.rad(Settings.SpinSpeed) * dt, 0))
end
end
end)
-- 태그에 따라 스테이지의 모든 장애물을 활성화합니다
local function setupStage(stage)
for _, part in stage:GetDescendants() do
if part:HasTag("Kill") then
part.Touched:Connect(killOnTouch)
end
end
end
-- 스테이지 하나를 무작위로 선택합니다
local function pickStage()
local all = stages:GetChildren()
return all[math.random(1, #all)]
end
-- 모델의 복사본을 타워 위에 올리고, 복사본과 새로운 꼭대기 높이를 반환합니다
local function stack(template, bottom)
local copy = template:Clone()
local box, size = copy:GetBoundingBox()
local lift = bottom - (box.Position.Y - size.Y / 2)
copy:PivotTo(copy:GetPivot() + Vector3.new(0, lift, 0))
copy.Parent = tower
return copy, bottom + size.Y
end
-- 아래에서 위로 새로운 무작위 타워를 만듭니다
local function buildTower()
tower = Instance.new("Model")
tower.Name = "Tower"
tower.Parent = workspace
local top = 0
for i = 1, Settings.StageCount do
local stage, newTop = stack(pickStage(), top)
top = newTop
setupStage(stage)
end
stack(ServerStorage.Finish, top)
end
buildTower()
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.