当前位置:网站首页>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
边栏推荐
- Give root password for maintenace (or press Control-D to continue):解决方法
- Cvpr2022|aconvnetforthe2020s & how to design neural network Summary
- [spark] (task8) pipeline channel establishment in sparkml
- 向数据库中注册用户名和密码的功能
- DynaSLAM II: Tightly-Coupled Multi-Object Tracking and SLAM 论文阅读
- IQR box diagram
- Office technical lecture: punctuation - English - Encyclopedia
- VDO-SLAM: A Visual Dynamic Object-aware SLAM System 论文阅读
- 从解读 BDC 自动生成的代码谈起,讲解 SAPGUI 的程序组成部分
- Mysql database (26): View
猜你喜欢
![Vdo-slam source code reading notes [2] local optimization and global optimization](/img/01/7ce7113737d9799ac2684788d9f08d.jpg)
Vdo-slam source code reading notes [2] local optimization and global optimization

用GNN做CV三大任务的新骨干,同计算成本性能不输CNN、ViT与MLP|中科院&华为诺亚开源...

Altium Designer重拾之开篇引入

Tidb Primary course experience 8 (Management Maintenance of Clusters, add a tikv Node)

Automatic Mapping of Tailored Landmark Representations for Automated Driving and Map Learning 论文阅读

Don't mistake "it informatization" for "super project"

JS global timer case

Commencez par interpréter le Code généré automatiquement par la BDC et expliquez les composantes du programme de l'interface graphique SAP.

微信web开发工具使用教程,公司开发web

DynaSLAM II: Tightly-Coupled Multi-Object Tracking and SLAM 论文阅读
随机推荐
The ability to register user names and passwords with the database
JS global timer case
由文件图形丢失,说明自己都不用自己开发的OFFICE
GNN is used as the new backbone of the three major tasks of CV, with the same cost performance as CNN, Vit and MLP | Chinese Academy of Sciences & Huawei Noah open source
Some words from ShareIt group
Recommended learning materials for Altium Designer
汇编语言入门-总结
What if the xshell evaluation period has expired? Follow the steps below to solve the problem!
Example of full page sliding screen at mobile terminal (sliding the whole screen up and down) (sorting)
'getWidth()' is deprecated,'getHeight()' is deprecated
Count the number and average value of natural numbers whose sum of bits within 100 is 7
20-year technical veteran gives up his CTO title! Why did the startup attract him?
Leetcode 96. Différents arbres de recherche binaires
六石编程学:以文字处理的位置,谈谈命名
JS prohibit copying page content
VDO-SLAM源码阅读笔记[2] local optimization和global optimization
Tidb elementary course experience 8 (cluster management and maintenance, adding a tikv node)
Alibaba cloud ECS server builds MySQL database
WTO MC12 restart agenda focuses on global economic recovery
OFFICE技术讲座:标点符号-英文-大全