El letrero
Lección 7 de 22 del curso Juego de Roblox: Tycoon de fábrica de Coddy.
Un letrero sobre la fábrica indica de quién es. El texto en la cara de una pieza es un SurfaceGui dentro de la pieza que contiene un TextLabel. Es fácil volver a encontrar las etiquetas con nombre, y una pequeña función mantiene todos los cambios del letrero en un solo lugar:
local gui = Instance.new("SurfaceGui")
gui.Parent = tycoon.Sign
local signLabel = Instance.new("TextLabel")
signLabel.Name = "Status"
signLabel.Size = UDim2.fromScale(1, 1)
signLabel.TextScaled = true
signLabel.Text = "Opening soon"
signLabel.Parent = guiUDim2.fromScale(1, 1) hace que la etiqueta ocupe toda la cara, y TextScaled ajusta las palabras a ella.
Desafío
IntermedioColoca un letrero sobre la fábrica que indique de quién es.
- En
tycoon.Sign, añade un SurfaceGui que contenga un TextLabel llamadoStatusque lo ocupe por completo, con texto escalado que digaStep on the green pad to claim this factory. - Escribe
setSign(text), que establece el Text de esa etiqueta. - Cuando se reclame la fábrica, llama a
setSign(player.Name .. "'s Factory").
Pulsa «Jugar» y pisa la plataforma verde: el letrero mostrará tu nombre. Después, pulsa «Comprobar».
Pruébalo tú mismo
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")
local Settings = require(game.ReplicatedStorage.Settings)
local tycoon = workspace.Tycoon
local owner = nil
print("Ore is worth " .. Settings.OreValue .. " Cash")
-- Cada jugador recibe Cash en la tabla de clasificación
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
end)
-- Lección 7: El Sign va aquí
-- Ore: una pieza pequeña que vale Cash y cae debajo de un dropper
local function dropOre(dropper)
local ore = Instance.new("Part")
ore.Name = "Ore"
ore.Size = Vector3.new(1, 1, 1)
ore.Color = Color3.fromRGB(150, 150, 160)
ore.Position = dropper.Position - Vector3.new(0, 2.5, 0)
ore:SetAttribute("Value", Settings.OreValue)
if math.random() < Settings.GoldChance then
ore.Color = Color3.fromRGB(255, 200, 40)
ore.Material = Enum.Material.Neon
ore:SetAttribute("Value", Settings.OreValue * 5)
end
ore.Parent = workspace
Debris:AddItem(ore, 20)
end
local function startDropper(dropper)
task.spawn(function()
while dropper:IsDescendantOf(workspace) do
dropOre(dropper)
task.wait(Settings.DropInterval)
end
end)
end
-- La cinta transportadora mueve todo lo que se encuentra sobre ella
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(Settings.BeltSpeed, 0, 0)
-- El colector convierte Ore en Cash
tycoon.Collector.Touched:Connect(function(hit)
if hit.Name == "Ore" then
local value = hit:GetAttribute("Value")
hit:Destroy()
if owner then
owner.leaderstats.Cash.Value += value
end
end
end)
-- Reclamación: el primer jugador que pisa la plataforma se convierte en dueño de la fábrica
local claimPad = tycoon.ClaimPad
claimPad.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not owner then
owner = player
claimPad.Color = Color3.fromRGB(120, 120, 120)
claimPad.Material = Enum.Material.SmoothPlastic
for _, dropper in CollectionService:GetTagged("Dropper") do
if dropper:IsDescendantOf(workspace) then
startDropper(dropper)
end
end
end
end)
Todas las lecciones de Juego de Roblox: Tycoon de fábrica
2Tu imperio
Reclama la fábricaPractica por tu cuenta: Playground de Roblox