사라지는 계단
Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 21개 중 7번째.
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)를 작성하세요. Touched 이벤트에서 캐릭터가 닿았고 속성Gone이 설정되어 있지 않으면, 그 값을 true로 설정하세요.Settings.VanishDelay만큼 기다린 다음 Transparency를0.8로 설정하고 CanCollide를 false로 설정하세요.Settings.VanishTime만큼 기다린 다음 두 설정을 원래대로 되돌리고Gone을 nil로 설정하세요.setupStage에서Vanish태그가 있는 파트에 이 함수를 호출하세요.
‘플레이’를 누르고 유리 계단 위에서 멈추세요. 계단이 희미해졌다가 다시 나타납니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
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
-- Lesson 7: Vanishing Steps 코드는 여기에 들어갑니다
-- 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()
Roblox 게임: 끝없는 타워의 모든 레슨
직접 연습해 보세요: Roblox 플레이그라운드