当前位置:网站首页>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 .
边栏推荐
- Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
- ES6 grammar summary -- Part I (basic)
- @The difference between Autowired and @resource
- What is the maximum length of MySQL varchar field
- [esp32 learning-1] construction of Arduino esp32 development environment
- [offer78] merge multiple ordered linked lists
- Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
- Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
- Single chip Bluetooth wireless burning
- Amba, ahb, APB, Axi Understanding
猜你喜欢
(1) Introduction Guide to R language - the first step of data analysis
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
Vulnhub target: hacknos_ PLAYER V1.1
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
2021.11.10汇编考试
Générateur d'identification distribué basé sur redis
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
idea中导包方法
Navigator object (determine browser type)
ES6 grammar summary -- Part 2 (advanced part es6~es11)
随机推荐
Programmers can make mistakes. Basic pointers and arrays of C language
关于Gateway中使用@Controller的问题
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Unity场景跳转及退出
ESP学习问题记录
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
程序设计大作业:教务管理系统(C语言)
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
基於Redis的分布式ID生成器
Page performance optimization of video scene
Mysqldump error1066 error solution
Arduino get random number
如何给Arduino项目添加音乐播放功能
Latex learning
Redis based distributed locks and ultra detailed improvement ideas
1081 rational sum (20 points) points add up to total points
Detailed explanation of truncate usage
JS正则表达式基础知识学习
MySQL takes up too much memory solution
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口