요약
속성
상속된 멤버
코드 샘플
게임 상태 텍스트
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- "GameState"라는 StringValue를 ReplicatedStorage에 배치합니다.
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- 이 코드를 TextLabel에 배치합니다.
local textLabel = script.Parent
-- TextColor3에 사용할 몇 가지 색상입니다.
local colorNormal = Color3.new(0, 0, 0) -- 검정
local colorCountdown = Color3.new(1, 0.5, 0) -- 주황
local colorRound = Color3.new(0.25, 0.25, 1) -- 파랑
-- 게임 상태가 변경될 때 TextLabel을 업데이트하기 위해 이 함수를 실행합니다.
local function update()
-- 텍스트를 업데이트합니다.
textLabel.Text = "상태: " .. vGameState.Value
-- 현재 게임 상태에 따라 텍스트의 색상을 설정합니다.
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- 패턴: 시작할 때 한 번 업데이트하고 vGameState가 변경될 때도 업데이트합니다.
-- 항상 가장 최신의 GameState를 볼 수 있어야 합니다.
update()
vGameState.Changed:Connect(update)API 참조
속성
Font
코드 샘플
모든 글꼴 보기
local frame = script.Parent
-- 각 글꼴을 표시하는 TextLabel 생성
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- 텍스트 속성 설정
textLabel.Text = font.Name
textLabel.Font = font
-- 일부 렌더링 속성
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- 텍스트 높이에 맞게 프레임 크기 조정
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- 부모 프레임에 추가
textLabel.Parent = frame
end
-- 프레임을 목록으로 레이아웃(이미 레이아웃이 아닌 경우)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end폰트 순환
local textLabel = script.Parent
while true do
-- 모든 다른 폰트를 반복합니다
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
endFontSize
Text
코드 샘플
사라지는 배너
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"내 게임에 오신 것을 환영합니다!",
"재미있게 놀아보세요!",
"제안해 주세요!",
"다른 플레이어에게 친절하세요!",
"다른 플레이어를 괴롭히지 마세요!",
"상점을 확인해 보세요!",
"팁: 죽지 마세요!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- 0단계: 아무것도 하기 전에 사라지게 함
fadeOut:Play()
task.wait(tweenInfo.Time)
-- 1단계: 마지막에 표시되지 않았던 콘텐츠 선택
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- 다음 번에 동일한 것을 표시하지 않도록 해야 함
lastIndex = index
-- 2단계: 콘텐츠 표시
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end텍스트의 이모지
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "나는 " .. mood .. " 기분이야! " .. face
task.wait(1)
end
endTextBounds
코드 샘플
동적인 텍스트 박스 크기
local textBox = script.Parent
-- 텍스트 박스가 될 수 있는 가장 작은 크기
local minWidth, minHeight = 10, 10
-- 입력하는 동안 텍스트가 약간 흔들리지 않도록 정렬 설정
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top
local function updateSize()
textBox.Size = UDim2.new(0, math.max(minWidth, textBox.TextBounds.X), 0, math.max(minHeight, textBox.TextBounds.Y))
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)TextColor
TextColor3
코드 샘플
카운트다운 텍스트
-- 이 코드를 TextLabel/TextButton 내의 LocalScript에 배치하세요
local textLabel = script.Parent
-- TextColor3와 함께 사용할 몇 가지 색상
local colorNormal = Color3.new(0, 0, 0) -- 검정색
local colorSoon = Color3.new(1, 0.5, 0.5) -- 빨간색
local colorDone = Color3.new(0.5, 1, 0.5) -- 초록색
-- 무한 루프
while true do
-- 10에서 1까지 카운트 다운
for i = 10, 1, -1 do
-- 텍스트 설정
textLabel.Text = "시간: " .. i
-- 남은 시간에 따라 색상 설정
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "시작!"
textLabel.TextColor3 = colorDone
task.wait(2)
endTextSize
코드 샘플
"쿵!" 텍스트
local textLabel = script.Parent
textLabel.Text = "쿵!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
endTextStrokeTransparency
코드 샘플
텍스트 하이라이트 진동
local textLabel = script.Parent
-- 하이라이트가 얼마나 빨리 깜빡일지
local freq = 2
-- 노란색 하이라이트 색상으로 설정
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin은 -1에서 1 사이에서 진동하므로, 범위를 0에서 1로 변경합니다:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
endTextWrap
TextWrapped
코드 샘플
긴 텍스트 줄 바꿈
local textLabel = script.Parent
-- 이 텍스트 줄 바꿈 데모는 200x50 px 사각형에서 가장 잘 표시됩니다.
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- 철자할 내용을 일부 포함합니다.
local content = "여기에 UI 요소의 너비를 "
.. "결국 초과할 긴 문자열이 있습니다. "
.. "줄 바꿈을 형성합니다. 매우 긴 문단에 유용합니다."
-- 두 글자씩 텍스트를 철자하는 함수
local function spellTheText()
-- 콘텐츠 길이만큼 반복합니다.
for i = 1, content:len() do
-- 콘텐츠의 부분 문자열 가져오기: 1부터 i까지
textLabel.Text = content:sub(1, i)
-- 상자에 맞지 않으면 텍스트 색상을 설정합니다.
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- 검은색
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- 빨간색
end
-- 짝수 길이에서 잠시 기다립니다.
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- 줄 바꿈 사용 안 함으로 텍스트를 철자합니다.
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- 줄 바꿈 사용으로 텍스트를 철자합니다.
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- 텍스트 크기 조정 사용으로 텍스트를 철자합니다.
-- 참고: 텍스트가 UI 요소에 맞기 위해 축소되어야 할 때 텍스트가 빨간색으로 변합니다. (TextFits = false)
textLabel.TextScaled = true
-- 참고: TextScaled가 true일 때 TextWrapped가 암묵적으로 활성화됩니다.
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
endTextXAlignment
코드 샘플
텍스트 정렬
-- 이 코드를 TextLabel/TextButton/TextBox 안의 LocalScript에 붙여넣으세요
local textLabel = script.Parent
local function setAlignment(xAlign, yAlign)
textLabel.TextXAlignment = xAlign
textLabel.TextYAlignment = yAlign
textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end
while true do
-- TextXAlignment 및 TextYAlignment 열거형 항목을 모두 반복합니다
for _, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
for _, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
setAlignment(xAlign, yAlign)
task.wait(1)
end
end
end