当前位置:网站首页>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 .
边栏推荐
猜你喜欢
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
NRF24L01故障排查
level16
JS数组常用方法的分类、理解和运用
Amba, ahb, APB, Axi Understanding
open-mmlab labelImg mmdetection
Symbolic representation of functions in deep learning papers
程序设计大作业:教务管理系统(C语言)
JS变量类型以及常用类型转换
Database course design: college educational administration management system (including code)
随机推荐
[offer78] merge multiple ordered linked lists
Unity场景跳转及退出
程序员老鸟都会搞错的问题 C语言基础 指针和数组
Minio file download problem - inputstream:closed
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
Expected value (EV)
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
[leetcode19]删除链表中倒数第n个结点
Working principle of genius telephone watch Z3
Arduino JSON data information parsing
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
Vscode basic configuration
Générateur d'identification distribué basé sur redis
map文件粗略分析
[leetcode19] delete the penultimate node in the linked list
Pat 1097 duplication on a linked list (25 points)
VSCode基础配置