当前位置:网站首页>Teach you unity scene switching progress bar production hand in hand
Teach you unity scene switching progress bar production hand in hand
2022-07-28 20:37:00 【_ Mr orange】
30 Seconds teach you Unity Scene switching progress bar
Hello everyone , I'm an orange , What I bring to you today is Unity Tutorial of scene switching progress bar .
*,*◦*,*◦*,*◦*,-------------------- Gorgeous dividing line --------------------*◦*,*◦*,*◦*,*◦*,*◦
First of all, ask a question : Why use the progress bar , And when to use the progress bar ?
answer : There are some scenes , It contains a lot of resources , For example, a big game scene , Loading is often slow . This is the time , If you don't do anything , In the process of scene loading , Users will think " Game stuck " 了 , So use a progress bar to transition , Increase the game experience . Don't talk much , Go straight to talent !
One 、 Create game scenes and build panels UI
First , We create a game scene
Then we build a new UI->>Panel
Let's create another one Skuder( Slider bar ) If a little friend doesn't know Skuder What is it? , You can check it out first Unity Of UGUI Tutorial again
Just like this. tips: Press on the keyboard T Then select the border with the mouse , Hold down Ait key It can be magnified proportionally ~
We could be here , Modify the style of the sliding block
My settings are ready , I don't know what you are ?
Choose them all here , Then set the anchor , It can adapt to the resolution of different devices ~
My progress bar is probably like this . Have you finished your ?
Two 、 Add code
We build a new one C# Script be known as LoadSceneManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LoadSceneManager : MonoBehaviour
{
public GameObject loadScreen;// Panel showing progress bar
public Slider slider;// Slide bar component
public Text text;// Text showing percentage
}
When it's defined , Let's go back to Unity To assign . Then add Button Binding events for ( The button for you to switch scenes )
When the assignment is complete Let's continue to write code
(1) After loading, enter the complete code of the scene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadSceneManager : MonoBehaviour
{
public GameObject loadScreen;// Panel showing progress bar
public Slider slider;// Slide bar component
public Text text;// Text showing percentage
// Don't forget to add a click event to the button
public void LoadNextLevel()
{
StartCoroutine(Loadlevel());
}
IEnumerator Loadlevel()
{
loadScreen.SetActive(true);
AsyncOperation operation = SceneManager.LoadSceneAsync("Main");
while (!operation.isDone)//isDone Whether to complete the progress bar
{
slider.value = operation.progress;
text.text = operation.progress * 100 + "%";// percentage
if (operation.progress>=0.9f)// If the progress bar has arrived 90%
{
slider.value = 1; // Then make the value of the progress bar into 1
text.text = " Loading complete !";
}
yield return null;
}
}
}
(2) Loading complete After pressing the key Enter the complete code of the scene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadSceneManager : MonoBehaviour
{
public GameObject loadScreen;// Panel showing progress bar
public Slider slider;// Slide bar component
public Text text;// Text showing percentage
public void LoadNextLevel()
{
StartCoroutine(Loadlevel());
}
IEnumerator Loadlevel()
{
loadScreen.SetActive(true);
AsyncOperation operation = SceneManager.LoadSceneAsync("Main");//(SceneManager.GetActiveScene().buildIndex+1);
operation.allowSceneActivation = false;// Whether to allow loading new scenes ? You need to automatically jump after loading There is no need to add this sentence
while (!operation.isDone)//isDone Whether to complete the progress bar
{
slider.value = operation.progress;
text.text = operation.progress * 100 + "%";// percentage
if (operation.progress>=0.9f)// If the progress bar has arrived 90%
{
slider.value = 1; // Then make the value of the progress bar into 1
text.text = " Please click on the screen to continue !";
if (Input.anyKey)// If you click any key
{
operation.allowSceneActivation = true;// You can jump to the scene
}
}
yield return null;
}
}
}
.
3、 ... and 、 Final effect
Four 、 Conclusion
Inferior to silicon step , A thousand miles .
Don't product the little stream , Beyond into the sea .
Make a little progress every day Thank you for watching .
Feel helpful to yourself , Welcome to your attention 、 Collection 、 forward !
边栏推荐
- Configure Windows Server + install MySQL database on the server + Remote Access database
- Use of DDR3 (axi4) in Xilinx vivado (2) read write design
- 【pytorch】LSTM神经网络
- Wildcard ssl/tls certificate
- Shanghai Jiaotong University joined hands with Taobao to set up a media computing laboratory: promoting the development of key technologies such as video super score
- Clock distribution of jesd204 IP core (ultrascale Series)
- 产品力大幅提升 新款福特探险者发布
- Redis review summary
- Does any elder brother know how to solve the huge flinksql log
- [pytorch] LSTM neural network
猜你喜欢
Linxu [permission, sticky bit]
Use of DDR3 (axi4) in Xilinx vivado (1) create an IP core
CM4 development cross compilation tool chain production
读取json配置文件,实现数据驱动测试
Torch. NN. Linear() function
Dsactf July re
C language data 3 (1)
太空射击第11课: Sound and Music
Linux Installation MySQL (pit filling version)
[task01: getting familiar with database and SQL]
随机推荐
Linxu [permission, sticky bit]
卡通js射击小游戏源码
太空射击第14课: 玩家生命
C# 委托 delegate 的理解
[pytorch] LSTM neural network
Raspberrypico serial communication
弹出模态框
js网页黑白背景开关js特效
GRU神经网络
Wust-ctf2021-re school match WP
How to make the design of governance structure more flexible when the homogenization token is combined with NFT?
华为云数字资产链,“链”接数字经济无限精彩
New fruit naming (DP is similar to the longest common subsequence)
DSACTF7月re
LeetCode_位运算_中等_260.只出现一次的数字 III
Other IPS cannot connect to the local redis problem solving and redis installation
Use of DDR3 (axi4) in Xilinx vivado (1) create an IP core
Usage Summary of thymeleaf
Vivado design single cycle CPU
太空射击第13课: 爆炸效果