当前位置:网站首页>Unity2D horizontal version of the game tutorial 10 - scene control
Unity2D horizontal version of the game tutorial 10 - scene control
2022-08-06 13:13:00 【really okay duck】
We reset the game when the character falls off the map
We create an empty project in Hierarchy, name it DeathLine, which is the death line, we add a box collider to it, adjustclick the collider

We want to use this collider as a trigger, so we check Is Trigger
Since we use Trigger, we need to modify the Tag of DeathLine, we create a Tag of DeathLine and give this Tag to DeathLine

We also used Trigger when collecting items, so similar to collecting items, we slightly modify the code when collecting items

We put the code for collecting items and dying to reset the game in the trigger
We want to reset the game when the character hits the line of death, here we need to use the scene control (SceneManager), we first add the scene controlnamespace

Scene controls can reload the scene and reset the game.There are many ways to load a scene. We can directly load the name of the scene or the number of the scene. Here we directly get the current scene to load and write a separate function

We need to call this function in the trigger. Here we use Invoke to call the Restart function. Invoke can set a delay of a few seconds to execute the function to be called. Here we set a delay of two seconds to call the Restart function

Note: The following is the expanded content, you may not read it, the above shall prevail
We can also use the scene number to load the scene. How do you see this number? We file->Bulid Settings, we can see that it has been addedA scene, this is our scene.

Its number is the 0 displayed on the right. We can drag the scene into more levels we create later, and the number will increase in turn. We load different scenes through the scene number, which will be used when creating menus later.Numbering.We can reset the game here and directly load the number of the current scene

Finally, if there are any mistakes or omissions, please correct me!
边栏推荐
猜你喜欢
随机推荐
GDB/MI 命令总结
速览muduo组成结构
具体的多路分发器:EPollPoller
干货 | 那些鬼斧神工的池化操作,看完我炸裂!
pytorch的自动求导和简单的线性函数机器学习
GD32E103 USB official library + STM32CubeMX
SQL图解面试题:人均付费如何分析?(分组、条件汇总)
AVS视频编码标准的演变:20年来的创新与发展
验证日期格式
Kubernetes 集群 Ingress 网关
多重背包问题 ← 规模小时可转化为0-1背包问题
Security on the seventh day to practice after class
智慧城市系列-1
解析隐式类型转换操作operator double() const,带你了解隐式转换危害有多大
解决spacedesk卸载/重装软件时显示 指定的账户已存在
报错:C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\cuda\Indexing.cu:699: block: [9,0,0],
非法字符: ‘\ufeff‘解决方案
【MySQL —— 事务】四大特性、隔离级别
40度高温,如何通过SOLIDWORKS找到室内最凉快的地方?
【Web3 系列开发教程——创建你的第一个 NFT(5)】使用 Ethers.js 铸造 NFT | 测试用例









