当前位置:网站首页>Unity scene jump and exit
Unity scene jump and exit
2022-07-06 12:33:00 【SQ Liu】
brief introduction :
Unity Realize simple jump of each scene in , And click “ Exit scene ” Close the interface .
Realization effect :
Implementation steps :
One 、 New scene
In the project you created , Add several scenarios that need to jump , Here we use 4 Take the jump between scenes as an example .4 The scene names are shown in the following figure .
In the scene above , You can first create a corresponding scene name 3D object , for example , scene Capsule in , You can create several capsules Capsule( As shown in the figure below ); scene Cube in , You can create several cubes Cube; scene Sphere in , You can create several spheres Sphere. What specific scenarios are created , According to your respective projects , And the scene that needs to complete the jump , Here is just a case .
Two 、 Create jump button
1、 As shown in the figure below , establish UI-Button.
2、 Modify canvas Canvas Of UI Scale Mode And its resolution .
3、 modify Button name , See the name and know the meaning , Prevent confusion caused by adding other buttons later , The specific operation is shown in the figure below .
4、Ctrl+D Copy 4 Share , Rename their buttons to BtnCube,BtnMain,BtnSphere,BtnTuiChu, And adjust their position in the canvas , As shown in the figure below .
3、 ... and 、 Add code
1、 Create a new one called “Scripts” Folder , Used to store all C# Script .
2、 All jump codes are as follows :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangJingTiaoZhuan : MonoBehaviour
{
public void TiaoZhuanCapsule()
{
SceneManager.LoadScene("Capsule");
}
public void TiaoZhuanCube()
{
SceneManager.LoadScene("Cube");
}
public void TiaoZhuanMain()
{
SceneManager.LoadScene("Main");
}
public void TiaoZhuanSphere()
{
SceneManager.LoadScene("Sphere");
}
public void TuiChuChangJing()
{
//#if UNITY_EDITOR
//UnityEditor.EditorApplication.isPlaying = false;// Exit in editing state
//#else
Application.Quit();// Package and compile and exit
//#endif
}
}
Four 、 Add button event registration
1、 Drag the script to Canvas in , As shown in the figure below .
2、 The specific operation is shown in the figure below .
3、 The reason for adding the following buttons to respond to events is the same as above , Be careful not to add dislocation to the corresponding event .
4、 When all are added , Save the current scene .
5、 Mouse selected Canvas and EventSystem, Right click and select Copy Copy, As shown in the figure below .
6、 Double click the mouse to enter the scene Cube, Then paste Paste In the previous scene Canvas.
7、 additional Main Scene and Sphere The scene operation steps are the same .
8、 Click on File, choice Build Settings, Drag in all the scenes that need to jump , As shown in the figure below .
notes : This step must have , Otherwise, the scene to jump will not be found after running !!
9、 thus , Jump switching between different scenes , And the exit scenario operation is completed .
5、 ... and 、 Engineering release
1、 Click on File, choice Build Settings, choice Player Settings, Modify some of its properties , Click when finished “Build” that will do .
2、Build After completion , Open its folder , Double-click to open “TiaoZhuan.exe” The program is ready to run .
边栏推荐
- level16
- What is the maximum length of MySQL varchar field
- Arduino get random number
- Kconfig Kbuild
- Redis based distributed ID generator
- SVN更新后不出现红色感叹号
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- Symbolic representation of functions in deep learning papers
- Page performance optimization of video scene
- JUC forkjoin and completable future
猜你喜欢
ESP学习问题记录
js 变量作用域和函数的学习笔记
Understanding of AMBA, AHB, APB and Axi
Kconfig Kbuild
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
ES6语法总结--下篇(进阶篇 ES6~ES11)
JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
Kconfig Kbuild
Classification, understanding and application of common methods of JS array
随机推荐
dosbox第一次使用
Basic operations of databases and tables ----- creating data tables
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
Walk into WPF's drawing Bing Dwen Dwen
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data
[offer29] sorted circular linked list
History object
Kconfig Kbuild
Conditional probability
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
Types de variables JS et transformations de type communes
JS 函数提升和var变量的声明提升
VIM command line notes
Minio file download problem - inputstream:closed
@Autowired 和 @Resource 的区别
Page performance optimization of video scene
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
[899]有序队列
Gateway fails to route according to the service name, and reports an error service unavailable, status=503