킬 브릭
Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 18개 중 4번째.
모든 장애물 코스에는 닿으면 안 되는 빨간색 파트가 있습니다. 스테이지에서는 어떤 인스턴스에나 붙일 수 있는 라벨인 태그로 표시합니다. 빨간색 스트립에는 Kill 태그가 붙어 있습니다:
print(part:HasTag("Kill")) --> true태그를 사용하면 큰 게임도 간단하게 유지할 수 있습니다. 스테이지 제작자는 파트에 태그만 붙이면 되고, 함수 하나로 태그가 붙은 모든 파트를 작동시킬 수 있습니다. 타워의 스테이지는 복사본이므로, 생성된 후에 설정하세요. GetDescendants는 스테이지 안의 모든 파트를 깊이에 상관없이 나열합니다:
for _, part in stage:GetDescendants() do
if part:HasTag("Kill") then
part.Touched:Connect(killOnTouch)
end
endHealth를 0으로 설정하세요. 무엇이든 닿을 수 있으므로, 닿은 물체의 모델에 Humanoid가 있는지 먼저 확인하세요. 이 레슨에서는 모든 스테이지가 KillBricks이므로 직접 시도해 볼 수 있습니다.
챌린지
쉬움killOnTouch(hit)를 작성하세요. 접촉한 대상의 모델에 Humanoid가 있으면 해당 대상의 Health를 0으로 설정합니다.setupStage(stage)를 작성하세요.stage:GetDescendants()에 있는 모든 파트 중Kill태그가 지정된 파트의Touched를killOnTouch에 연결합니다.buildTower에서 쌓는 각 스테이지마다setupStage(stage)를 호출하세요.
Play를 누르고 빨간 줄을 뛰어넘으세요. 그런 다음 Check를 누르세요.
직접 해보기
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")
-- 모든 플레이어에게 leaderboard의 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)
-- 무작위로 스테이지 하나 선택
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()
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.