unity3d修改场景
What the Scene Management library is most used for is jumping between scenes. It is one of the most simplest things to do but is vital to the creation of a game
场景管理库最常用的是在场景之间跳转。 这是最简单的事情之一,但对创建游戏至关重要
Let us now see how it is actually done
现在让我们看看它是如何完成的
Now in your Assets folder, create 2 new scenes and name them “Scene1” and “Scene2”.
现在,在您的Assets文件夹中,创建2个新场景,并将它们分别命名为“ Scene1”和“ Scene2” 。
To create a new Scene,Right-Click in the assets panel area and select Create > Scene.
要创建新的场景,请右键单击资产面板区域,然后选择“ 创建”>“场景”。
Here what we aim to do, is that we should be able to skip between scenes on the press of a button (UI element). We can do this in various ways but to facilitate understanding, we will be using the simplest way. We will be creating a SceneChanger Object which will handle all the scene changing code (whatever little there is of it).
我们的目标是要通过按一下按钮(UI元素)在场景之间跳转。 我们可以通过多种方式来做到这一点,但是为了促进理解,我们将使用最简单的方式。 我们将创建一个SceneChanger对象,该对象将处理所有场景更改代码(几乎不包含任何代码)。
Also generally when a scene is changed from one to another, all the instances of the game objects, scripts, etc. belonging to that scene are destroyed and the ones from the new one are loaded. Another method is to use the DontDestroyOnLoad() function which will maintain an object reference across scene changes but this well be touched upon in another tutorial
同样,通常,当一个场景从一个场景切换到另一个场景时,属于该场景的游戏对象,脚本等的所有实例都将被销毁,而新实例中的实例将被加载。 另一种方法是使用DontDestroyOnLoad()函数,该函数将在场景变化时维护对象引用,但是在另一教程中会对此进行很好的介绍。
SceneChanger对象创建和预制 (SceneChanger Object Creation and Prefab)
Alright, so back in Unity, in the Hierarchy tab of "Scene1", create an Empty Game Object and name it "SceneChanger"(do it yourself).
好了,回到Unity中,在