且听爆竹声声慈 发表于 2021-5-31 13:11:58

对话文字显示,实现一个字一个字显示

这个功能可自行封装在moudle中,可以运用在需要进行对话的游戏,代码比较简单好学。
local a = true --防止多次执行该函数导致重复显示
local seep = 0.3 --文字显示速度
function dh(UiText,text)
    if a == true then
          a = false
          UiText.Text = ''
          local i = 1

          while true do
                  wait(seep)
                  local c = string.sub(text,i,i)
                     local b = string.byte(c)

                  if b > 128 then
                          UiText.Text = UiText.Text .. string.sub(text,i,i+2)
                          i = i + 3
                  else
                          if b == 32 then
                                  UiText.Text = UiText.Text .. ' '
                          else
                                  UiText.Text = UiText.Text .. c
                          end
                         i = i + 1
                  end

                  if i > #text then
                          break
                  end
          end       
          a = true
    end
end

--实例
local ui = script.Parent --这是一个带有Text属性的文本
dh(ui,"我是一段比较长的文字..........")
页: [1]
查看完整版本: 对话文字显示,实现一个字一个字显示