当前位置:网站首页>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 .


边栏推荐
- 数据库课程设计:高校教务管理系统(含代码)
- [offer29] sorted circular linked list
- Classification, understanding and application of common methods of JS array
- [leetcode622]设计循环队列
- SSD technical features
- Arm pc=pc+8 is the most understandable explanation
- 基於Redis的分布式ID生成器
- JS数组常用方法的分类、理解和运用
- Single chip Bluetooth wireless burning
- js 变量作用域和函数的学习笔记
猜你喜欢

Basic operations of databases and tables ----- classification of data

编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)

Kconfig Kbuild

Whistle+switchyomega configure web proxy

(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析

Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights

Arduino JSON data information parsing

Latex learning

Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0

基于Redis的分布式锁 以及 超详细的改进思路
随机推荐
[Leetcode15]三数之和
Imgcat usage experience
Kconfig Kbuild
SSD technical features
單片機藍牙無線燒錄
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
燕山大学校园网自动登录问题解决方案
E-commerce data analysis -- salary prediction (linear regression)
Latex learning
Types de variables JS et transformations de type communes
Mysqldump error1066 error solution
MySQL時間、時區、自動填充0的問題
[offer29] sorted circular linked list
HCIP Day 12
About using @controller in gateway
Servlet
CUDA C programming authoritative guide Grossman Chapter 4 global memory
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
Conditional probability