当前位置:网站首页>Unity typewriter to automatically roll text to the bottom of the text box
Unity typewriter to automatically roll text to the bottom of the text box
2022-06-10 13:05:00 【Lin fengyiyi】
The effect is shown in the figure :

Steps are as follows :
One 、 stay Canvas——Image Next , Create a ScrollView, Be careful , Here I want not to let white Image Block my background , Right here. ScrollView Upper Image The color of has been modified , Make it transparent Alpha Change it to 1( Be careful not to change to 0, Otherwise you won't see the text )

Two 、 Yes ScrollView Make the following changes :

3、 ... and 、 Yes Content Make the following changes :

Four 、 Yes Text Make the following changes :

5、 ... and 、 The typewriter script is as follows :
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace MyController
{
public class DaZiJiController : MonoBehaviour
{
public Text m_tweenText;
[Range(1, 30)]
public float m_speed = 1.0f;
public AudioClip m_audio;
private bool m_canTween = false;
private string m_totalStr;
private float m_timeChange = 0.0f;
public Scrollbar verticalScrollbar;
void Start()
{
BeginTextShow();
}
void Update()
{
// If you can start animation
if (m_canTween)
{
// Determine whether the text should end the animation
if (m_tweenText.text.Equals(m_totalStr))
{
// end
TextTweenFinsh();
}
else
{
// not finished , Text animation
m_tweenText.text = m_totalStr.Substring(0, (int)(m_speed * m_timeChange));
m_timeChange += Time.deltaTime;
StartCoroutine(ScrollBarBottom());
}
}
}
void LateUpdate()
{
if(Input.GetKeyDown(KeyCode.A))
{
//TextTweenFinsh();
m_tweenText.text = " Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n" +
" Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n" +
" Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n" +
" Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n Thousands of birds fly away , The trail of man is gone , In a lonely boat, there are many rainbows , Fishing for snow in the cold river alone .\n";
BeginTextShow();
}
}
void BeginTextShow()
{
// Save the text beforehand
m_totalStr = m_tweenText.text;
// Empty Unity Text Text content
m_tweenText.text = "";
// Change time to zero
m_timeChange = 0f;
// Add audio components , And set the audio to be played
m_tweenText.gameObject.GetComponent<AudioSource>().clip = m_audio;
// Set the audio loop
m_tweenText.GetComponent<AudioSource>().loop = true;
m_tweenText.GetComponent<AudioSource>().volume = 0.4f;
// Play the audio
m_tweenText.GetComponent<AudioSource>().Play();
// You can start animation
m_canTween = true;
}
void TextTweenFinsh()
{
m_canTween = false;
m_tweenText.text = m_totalStr;
m_timeChange = 0.0f;
m_tweenText.GetComponent<AudioSource>().Stop();
//DestroyObject(m_tweenText.GetComponent<AudioSource>());
Debug.Log(" Trigger “ Typewriter end !” event ");
}
IEnumerator ScrollBarBottom()
{
yield return null;
verticalScrollbar.value = 0;
}
}
}
Demo Download link :
link :https://pan.baidu.com/s/15MijVu99gNqLvfCRIBSevQ
Extraction code :sk7m
边栏推荐
- Use soapUI tool to generate SMS interface code
- Vdo-slam source code reading notes [2] local optimization and global optimization
- 從解讀 BDC 自動生成的代碼談起,講解 SAPGUI 的程序組成部分
- 【Golang】创建有配置参数的结构体时,可选参数应该怎么传?
- 从解读 BDC 自动生成的代码谈起,讲解 SAPGUI 的程序组成部分
- 【深度学习】基于深度学习Autoencoder的信用卡欺诈异常检测,效果非常牛逼
- 阿里云ECS服务器搭建Mysql数据库
- 百度程序员删库被判9个月,手机号一键解绑功能发布,推特再向马斯克妥协,今日更多大新闻在此...
- JS translates Arabic numerals into Chinese capital figures, JS converts figures into capital amounts (sorting)
- Give root password for maintenace (or press Control-D to continue):解决方法
猜你喜欢

阿里云ECS服务器搭建Mysql数据库

Count the number and average value of natural numbers whose sum of bits within 100 is 7

JTAG-to-AXI Master调试AXI BRAM Controller

Wechat web development tool tutorial, the company develops Web

UML class diagram

从解读 BDC 自动生成的代码谈起,讲解 SAPGUI 的程序组成部分试读版

MySQL 服务演进

Introduction of Altium Designer

Slide the navigation fixed head upwards

Ant financial services Yang Jun: evolution of ant data analysis platform and application of data analysis methods
随机推荐
Vdo-slam: a visual dynamic object aware slam system paper reading
【Golang】创建有配置参数的结构体时,可选参数应该怎么传?
Automatic Mapping of Tailored Landmark Representations for Automated Driving and Map Learning 论文阅读
启牛能开户吗,启牛在APP上可以直接开通券商安全吗
If the files and graphics are lost, it means that you don't need the office developed by yourself
百度程序员删库被判9个月,手机号一键解绑功能发布,推特再向马斯克妥协,今日更多大新闻在此...
Unity3d uses URP rendering pipeline to realize ar shadow (shadow casting and transparent ground)
Practical cases, in-depth analysis
Case sharing and implementation introduction of SAP field service management and wechat integration
list. Remove (index) returns false, removal failed
Program, calculate 2/1+3/2+5/3+8/5 Value of. It is required to calculate the sum of the first n items and keep 2 decimal places (starting from the second item of the sequence, the numerator of each it
Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?
JTAG to Axi master debugging Axi Bram controller
TIDB 初級課程體驗 8 (集群的管理維護, 添加一個TIKV節點)
Timeline and logistics information. You don't need stepview at all
Leetcode 96. Different binary search trees
Comparison of two BigDecimal data types, addition, subtraction, multiplication and division, and formatting
Code free may event Microsoft low code matrix update; Multiple industry reports released
MySQL 服务演进
Good article sharing | 48 hour agile development introduction