킬 브릭
Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 21개 중 5번째.
모든 오비에는 절대 만지면 안 되는 빨간 파트가 있습니다. 스테이지에서는 어떤 인스턴스에든 붙일 수 있는 레이블인 태그로 표시합니다. 빨간 띠에는 Kill 태그가 붙어 있습니다:
print(part:HasTag("Kill")) --> true태그를 사용하면 대규모 게임도 간결하게 만들 수 있습니다. 스테이지 제작자는 파트에 태그만 붙이면 되고, 하나의 함수가 태그가 붙은 모든 파트를 작동하게 합니다. 타워의 스테이지는 복사본이므로, 스테이지를 만든 뒤 설정하세요. GetDescendants는 스테이지 안에 있는 모든 파트를 깊이에 상관없이 나열합니다:
for _, part in stage:GetDescendants() do
if part:HasTag("Kill") then
part.Touched:Connect(killOnTouch)
end
end생명을 끝내려면 Humanoid의 Health를 0으로 설정하세요. 무엇이든 접촉할 수 있으므로, 접촉한 캐릭터인 hit.Parent에 먼저 Humanoid가 있는지 확인하세요. 이 레슨에서는 모든 스테이지가 KillBricks이므로 직접 시험해 볼 수 있습니다.
챌린지
쉬움빨간 줄무늬를 치명적으로 만드세요.
killOnTouch(hit)를 작성하세요.hit.Parent(접촉한 캐릭터)에Humanoid가 있으면 해당 객체의Health를 0으로 설정하세요.setupStage(stage)를 작성하세요.Kill태그가 지정된stage:GetDescendants()의 모든 파트에 대해Touched를killOnTouch에 연결하세요.buildTower에서 쌓는 각 스테이지마다setupStage(stage)를 호출하세요.
‘플레이’를 누르고 빨간 줄무늬에 닿아 보세요. 죽으면 다시 생성됩니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
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)
-- Lesson 5: Kill Bricks는 여기에 들어갑니다
-- 아무 스테이지나 무작위로 선택합니다
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
end
stack(ServerStorage.Finish, top)
end
buildTower()
Roblox 게임: 끝없는 타워의 모든 레슨
직접 연습해 보세요: Roblox 플레이그라운드