unity3d修改场景_在Unity 3D中更改场景

本文介绍了如何在Unity 3D中实现场景间的切换,包括创建SceneChanger对象、预制件,以及构建UI交互,允许通过按钮在"Scene1"和"Scene2"之间切换。此外,还讲解了使用SceneManager类加载新场景的方法和创建UI元素的过程。
摘要由CSDN通过智能技术生成

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”

Changing Scene images

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中,在

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值