L'insegna
Lezione 7 di 22 del corso Gioco Roblox: Tycoon della fabbrica di Coddy.
Un cartello sopra la fabbrica indica a chi appartiene. Il testo sulla superficie di una parte è una SurfaceGui all'interno della parte, che contiene un TextLabel. Le etichette con un nome sono facili da ritrovare, e una piccola funzione mantiene tutte le modifiche al cartello in un unico posto:
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) fa sì che l'etichetta occupi tutta la superficie, mentre TextScaled adatta le parole a essa.
Sfida
MedioMetti un cartello sopra la fabbrica che indichi a chi appartiene.
- In
tycoon.Sign, aggiungi un SurfaceGui contenente un TextLabel chiamatoStatusche lo riempia, con testo ridimensionato che dicaStep on the green pad to claim this factory. - Scrivi
setSign(text), che imposta il Text di quell'etichetta. - Quando la fabbrica viene reclamata, chiama
setSign(player.Name .. "'s Factory").
Premi «Gioca» e sali sul tappetino verde: il cartello mostra il tuo nome. Poi premi «Verifica».
Provalo tu
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")
-- Ogni giocatore riceve Cash nella classifica
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)
-- Lezione 7: qui va il cartello
-- Ore: un piccolo pezzo che vale Cash, lasciato cadere sotto 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
-- Il nastro trasportatore trasporta tutto ciò che vi si trova sopra
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(Settings.BeltSpeed, 0, 0)
-- Il raccoglitore trasforma il minerale in 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)
-- Rivendicazione: il primo giocatore a salire sulla piattaforma diventa proprietario della fabbrica
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)
Tutte le lezioni di Gioco Roblox: Tycoon della fabbrica
Esercitati da solo: Playground Roblox