unity3d 添加脚本_在Unity 3D中添加和管理资产

unity3d 添加脚本

We see that our game looks pretty empty right now. So let's fix that. Grab an image that you would want to make your player. For example, we will be using this happy little star.

我们看到我们的游戏现在看起来很空白。 因此,让我们对其进行修复。 拿起您想成为播放器的图像。 例如,我们将使用这个快乐的小星星。

We have Mr. Star here on our Desktop so that we can easily access him. To add him into Unity, we will simply drag and drop the image into our Assets.

我们的桌面上有Star先生,以便我们可以轻松访问他。 要将他添加到Unity中,我们只需将图像拖放到Assets中即可

Unity 3D - Adding and Managing Assets

What we've done so far is just added the Star image into our project, but not into the current scene. To add it into the scene, just drag and drop the image from the Assets view into either the Scene View or the Hierarchy (Objects added in the Scene View get added to the Hierarchy automatically).

到目前为止,我们所做的只是将Star图像添加到我们的项目中,而不是添加到当前场景中。 要将其添加到场景中,只需将图像从“ 资产”视图拖放到“ 场景视图”或“ 层次结构”中 (添加到“场景视图”中的对象会自动添加到层次结构中)。

Objects that you add as images are stored as sprites when you're working in 2D. Sprites is Unity's way of remembering that you're using these images to work with them in 2 dimensions, not 3.

在2D模式下工作时,添加为图像的对象将存储为精灵Sprites是Unity记住您使用这些图像在2维而非3维上使用它们的方式。

Adding and Managing Assets in Unity

You've added just one image, and you already must have noticed quite some changes in different views in the Unity window. First of all, and what may seem to be most noticeable, is that the Inspector View is no longer empty with options such as, Sprite Renderer and Transform listed below. These are called Components and they're important.

您仅添加了一张图像,并且您已经注意到Unity窗口中不同视图中的许多变化。 首先,而且似乎是最值得注意的是,“ 检查器视图”不再是空的,下面列出了诸如“ Sprite Renderer”和“ Transform”之类的选项。 这些称为组件 ,它们很重要。

You see, Transform is a property of any object in Unity which stores some of its most basic data. What falls under basic data?

您会看到, Transform是Unity中任何存储其最基本数据的对象的属性。 什么属于基本数据

  • Every object has a Position.

    每个对象都有一个位置。

  • It has a Rotation angle.

    它具有旋转角度。

  • It has a Scale Factor.

    它具有比例因子。

These are the values which tell Unity where and how exactly an object is positioned in the game world. Try changing the X, Y and Z elements of these properties to different values to see what happens.

这些值告诉Unity对象在游戏世界中的位置和位置。 尝试将这些属性的XYZ元素更改为不同的值,看看会发生什么。

Sprite Renderer is a component which works with how your sprite (that is, your image) is handled on-screen. It has a few properties like the image to render, the color of the image (white means the image is unmodified), flips, and sorting layers. For now, we don't want to change anything around in the Sprite Renderer, so let's leave it as it is.

Sprite Renderer是一个组件,可用于在屏幕上处理Sprite(即图像)的方式。 它具有一些属性,例如要渲染图像,图像颜色 (白色表示图像未修改), 翻转排序层 。 目前,我们不希望在Sprite Renderer中进行任何更改,因此我们将其保留不变。

If you click the Play button now, you'll see that the image you added is now visible in-game! Woohoo! But, there's a blue background that you don't quite recall adding. That's because that background is added by the Camera in the scene. If you want to change that background color, simply click on the Main Camera in the Hierarchy, and then change the background color by clicking on the Background property for the Camera component in the Inspector.

如果现在单击“ 播放”按钮,您将看到添加的图像现在在游戏中可见! oo! 但是,有一个蓝色背景,您不太记得要添加。 这是因为该背景是由场景中的“摄像机”添加的。 如果要更改该背景色,只需在“ 层次结构”中单击“ 主摄像机 ”,然后在“ 检查器”中单击“ 摄像机”组件的“ 背景”属性即可更改背景色。

Adding and Managing Assets

So far, we've only added one asset. But as your project grows and gets bigger, and you add more and more assets, it may get difficult to manage all your assets. That's why making sure your assets are properly organized from the start reduces a lot of future headaches (Trust me, I've been a victim).

到目前为止,我们仅添加了一项资产。 但是,随着项目的发展和壮大,以及添加的资产越来越多,可能难以管理所有资产。 这就是为什么从一开始就确保您的资产得到正确组织的原因,这会减轻很多将来的麻烦(请相信我,我一直是受害者)。

You can organize your assets into folders, right click anywhere in the Assets section, and select, Create → Folder.

您可以将资产组织到文件夹中,右键单击“ 资产”部分中的任意位置,然后选择创建→文件夹

Adding and Managing Assets in unity

Unity是如何工作的? (How Unity Works?)

Let's stray away from working on Unity to dive into understanding how Unity actually works with games below the hood.

让我们远离对Unity的研究,深入了解Unity在引擎盖下的游戏中的实际工作方式。

Imagine you're a completely normal person. You're not a game designer or anything, you just go about your daily business.

想象你是一个完全正常的人。 您不是游戏设计师或其他任何人,您只是从事日常业务。

Imagine you go to see a play one day. You buy a ticket, you sit down at your seat, maybe buy some snacks on the way, in a mood to enjoy the evening.

想象你有一天去看一场戏。 您买了票,坐在您的座位上,也许在途中买了一些零食,以享受夜晚的心情。

Here's where the real fun starts. If its a play, what kind of things do you expect from it? Surely there's a stage on which everything happens. Also, a play isn't a play without a decorated stage and people moving on it, right? Who would want to stare at an empty stage for an hour, much less, pay for it? You could say there's a lot of stuff on the stage, a lot of objects.

真正的乐趣在这里开始。 如果这是一场戏,您会从中期待什么? 当然,有一个阶段,一切都会发生。 而且,一场戏不是没有装饰性舞台的戏,人们在继续前进,对吗? 谁愿意在一个空旷的舞台上凝视一个小时,少花点钱买单? 您可以说舞台上有很多东西,很多东西。

Most plays are usually divided into scenes. There could be a scene of a dark forest with huge trees and a lake with fairies around. There could be another scene of the inside of a castle, with gold paved everywhere and chandeliers hanging from the ceiling. Where I'm going with this is, there are different scenes in one play, where the objects on the stage could be different or even the same (One could use the same cutout of a rock in a mountain and near a mine)

大多数戏剧通常分为场景。 可能会出现一片茂密的黑暗森林和周围仙女湖的景象。 城堡内部可能还有其他场景,到处都是金色,天花板上悬挂着枝形吊灯。 我要去的地方是,一个剧本中有不同的场景,舞台上的物体可能不同甚至相同(一个人可以在山上和矿山附近使用相同的岩石切口)

Unity is simply one giant stage play. Everything in Unity happens in scenes. Your game's title screen will be a scene, the end credits will be a scene, your game-play will happen in a screen (or several of them), heck, even your options menu will be a scene. Every scene in Unity is made with objects, much like everything in a regular stage play. You're arranging cardboard cutouts in a stage play scene, whereas you're arranging things like audio sources, light sources, players, cameras and maps in a Unity scene.

团结只是一场大舞台剧 。 Unity中的一切都发生在场景中。 您游戏的标题屏幕将是一个场景,结束片数将是一个场景,您的游戏将在一个屏幕(或其中的几个屏幕)中发生,哎呀,甚至您的选项菜单也将是一个场景。 Unity中的每个场景都是由对象组成的,就像常规舞台剧中的一切一样。 您在舞台剧场景中布置纸板切口,而在Unity场景中布置诸如音频源,光源,播放器,照相机和地图之类的东西。

Actors in plays generally have scripts that tell them what they're supposed to do, act and say at any given time during the play. We can call the actors objects too, right? Human beings are also objects, after all. Similarly, some or all objects in a Unity scene may have scripts that tell them what to do, when to do it. Making these scripts, involve writing code (Usually C# or JavaScript) and attaching them to the objects you want the code to affect. For example, if we have a spaceship in our scene, we would write a piece of code for moving it around with the arrow keys. We would save that piece of code as a script, and then attach that script to the object that is your spaceship (Everything in a Unity scene is, in some way or the other, an object, remember).

戏剧中的演员通常都有剧本,可以告诉他们在剧中的任何特定时间应该做什么,要表演和说些什么。 我们也可以称演员为对象,对不对? 毕竟,人类也是对象。 类似地,Unity场景中的某些或所有对象可能都有脚本,该脚本告诉他们做什么,何时做。 制作这些脚本需要编写代码(通常是C#JavaScript )并将它们附加到您希望代码影响的对象上。 例如,如果我们的场景中有一艘太空飞船,我们将编写一段代码以使用箭头键将其移动。 我们会将这段代码另存为脚本,然后将该脚本附加到您的太空飞船上(在某种程度上,Unity场景中的所有对象都是一个对象,请记住)。

This is what Unity is all about, really. You're just making one, giant interactive stage play. As much as you're becoming a game designer by learning Unity, you're also becoming a stage play coordinator! (Well, not really)

实际上,这就是Unity的全部意义。 您只是在制作一个大型的互动舞台剧。 通过学习Unity成为游戏设计师的同时,您也成为舞台剧协调员! (嗯,不是真的)

翻译自: https://www.studytonight.com/game-development-in-2D/adding-and-managing-assets

unity3d 添加脚本

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值