Roblox · Сбор-а-тон · урок 5
Карта большая — добавим быстрые перемещения: список мест с картинками, клик переносит туда.
Синим — что добавляем на этом уроке.
Workspace └─ Teleports (Folder) └─ Лес (Part) — площадка, имя = название места └─ Decal (Decal) — картинка места StarterGui └─ ListGui (ScreenGui) ├─ TeleportButton (TextButton) — «Карта» ├─ TeleportFrame (Frame) — Visible выкл. │ └─ ScrollingList (ScrollingFrame) — UIGridLayout │ └─ Sample (Frame) — шаблон: LocationImage (ImageButton), LocationName └─ TeleportLocal (LocalScript)
Где: StarterGui → ListGui · LocalScript
Зачем: Список мест и перенос.
-- игроки
local Players = game:GetService("Players")
-- этот игрок
local player = Players.LocalPlayer
-- точки телепорта
local teleports = workspace:WaitForChild("Teleports")
-- ListGui
local gui = script.Parent
-- кнопка карты
local button = gui:WaitForChild("TeleportButton")
-- список мест
local frame = gui:WaitForChild("TeleportFrame")
-- прокрутка
local scrolling = frame:WaitForChild("ScrollingList")
-- шаблон
local sample = scrolling:WaitForChild("Sample")
-- кнопка
button.MouseButton1Click:Connect(function()
-- открыть / закрыть
frame.Visible = not frame.Visible
-- конец функции
end)
-- каждое место
for _, point in ipairs(teleports:GetChildren()) do
-- копия шаблона
local card = sample:Clone()
-- имя
card.Name = point.Name
-- подпись
card.LocationName.Text = point.Name
-- картинка места
local decal = point:FindFirstChildOfClass("Decal")
-- на кнопку
card.LocationImage.Image = decal and decal.Texture or ""
-- фон — цвет площадки
card.LocationImage.BackgroundColor3 = point.Color
-- показываем
card.Visible = true
-- в список
card.Parent = scrolling
-- клик по месту
card.LocationImage.MouseButton1Click:Connect(function()
-- персонаж
local character = player.Character
-- он есть
if character and character:FindFirstChild("HumanoidRootPart") then
-- переносим целиком над площадкой
character:PivotTo(point.CFrame + Vector3.new(0, 4, 0))
-- закрываем список
frame.Visible = false
-- конец проверки
end
-- конец функции
end)
-- конец перебора
endЗапусти Play (или Run) и убедись:
Roblox · Collect-a-thon · lesson 5
The map is big — let's add fast travel: a list of places with pictures; a click takes you there.
Blue — what we add in this lesson.
Workspace └─ Teleports (Folder) └─ Лес (Part) — a pad, name = the place name └─ Decal (Decal) — the place picture StarterGui └─ ListGui (ScreenGui) ├─ TeleportButton (TextButton) — "Карта" (map) ├─ TeleportFrame (Frame) — Visible off │ └─ ScrollingList (ScrollingFrame) — UIGridLayout │ └─ Sample (Frame) — template: LocationImage (ImageButton), LocationName └─ TeleportLocal (LocalScript)
Where: StarterGui → ListGui · LocalScript
Why: The list of places and travel.
-- players
local Players = game:GetService("Players")
-- this player
local player = Players.LocalPlayer
-- teleport points
local teleports = workspace:WaitForChild("Teleports")
-- ListGui
local gui = script.Parent
-- the map button
local button = gui:WaitForChild("TeleportButton")
-- the list of places
local frame = gui:WaitForChild("TeleportFrame")
-- scrolling
local scrolling = frame:WaitForChild("ScrollingList")
-- the template
local sample = scrolling:WaitForChild("Sample")
-- a button
button.MouseButton1Click:Connect(function()
-- open / close
frame.Visible = not frame.Visible
-- end of function
end)
-- each place
for _, point in ipairs(teleports:GetChildren()) do
-- a copy of the template
local card = sample:Clone()
-- name
card.Name = point.Name
-- the caption
card.LocationName.Text = point.Name
-- the place picture
local decal = point:FindFirstChildOfClass("Decal")
-- onto the button
card.LocationImage.Image = decal and decal.Texture or ""
-- background — the pad's color
card.LocationImage.BackgroundColor3 = point.Color
-- show it
card.Visible = true
-- into the list
card.Parent = scrolling
-- a click on a place
card.LocationImage.MouseButton1Click:Connect(function()
-- the character
local character = player.Character
-- it exists
if character and character:FindFirstChild("HumanoidRootPart") then
-- move the whole character above the pad
character:PivotTo(point.CFrame + Vector3.new(0, 4, 0))
-- close the list
frame.Visible = false
-- end of check
end
-- end of function
end)
-- end of loop
endPress Play (or Run) and make sure: