Get an offline copy of this page by clicking the libreoffice writer icon Exporter la page au format Open Document

GameObjects : Earth V 1.0

GameObjects are a very important concept in Unity. In Unity, everything that appears on the screen when your game is running comes from a GameObject: 3D objects, 2D sprites, the UI (User Interface), lights, cameras, C# scripts… Open the new empty project we created earlier. Unity created a default scene named “SampleScene.unity” and added just two GameObjects: a camera (named Main Camera) and a light (named Directional Light).

Creating Your First GameObject

To illustrate the concept of a GameObject, we’re going to create a 3D Earth. First, let’s find an Earth texture. In Google Images, type “earth texture” and download the texture you like best. Or download the one below

EARTH DAY MAP High Resolution 2K (2048×1024 pixels)

from the website https://www.solarsystemscope.com/textures There’s no need to use 4K textures or higher—this is a video game, so you always have to find the best balance between file size and quality.

In Unity, we’ll create a new “Textures” subfolder at the root of “Assets” (Create / Folder). Assets are all the source files for your game (3D models, textures, sounds, images, etc.).

From Windows File Explorer, copy and paste your earth texture into the “Textures” subfolder.

Now, go to the menu at the very top: GameObject / 3D Object / Sphere.

We create a sphere primitive directly in Unity. We have created a 3D sphere. The properties of the sphere GameObject appear in the panel on the right. Our GameObject is named “Sphere” and consists of 3 components.

The Different Components of the “Sphere” GameObject Components are building blocks that you can freely add to or remove from a GameObject.

A GameObject is essentially an empty container that always has a fixed “Transform” component to define its position, rotation, and size in space. After that, you’re free to add whatever components you want.

In our case, there are: – The “Sphere” component, which creates the 3D sphere object – The “Mesh Renderer” component, which renders the 3D object – The “Sphere Collider” component, which allows the 3D object to react to collisions

Modifying/Customizing Our GameObject

We’ll start by renaming our GameObject. It’s important to name things properly; otherwise, when your scene contains dozens of GameObjects, it will become unmanageable. Rename “Sphere” to “Earth.”

Collisions aren't important in this example, so we're going to remove (delete) the “Sphere Collider” component.

We’re now going to create a material so we can assign the texture to the sphere. Create a new folder at the root of the Assets folder and name it “Materials.” Double-click the folder you created to open it.

Now create a new material (Create / Material)

You will name this material “EarthMat.” Select this material; its properties will appear in the right-hand panel. Click the small dot (anchor) next to “BaseMap”. Select the earth texture (JPEG bitmap texture).

We're now going to assign the “EarthMat” material to our “Earth” sphere. Select the “Earth” GameObject in the left panel. Click the small anchor point next to Materials / Element 0. Select the “EarthMat” material.

Scene Rendering

There you go—our planet Earth is textured! Double-click “Earth” in the left panel (the one that lists all the GameObjects in the scene) to re-center the editor view on the sphere.

Now select the “Main Camera” in the left panel. In the bottom-right corner of the 3D view, you’ll see a preview of what the camera will see at runtime (when the game is running).

The Earth is a little too small—here are two solutions… – You can enlarge the sphere by changing its scale in the Transform component of the sphere’s GameObject. – Or, you can set the camera to a wider field of view.

Set “Field of view” to 10, select “Solid Color” for Clear Flags, and set the Background to black. To get pure black, all three R, G, and B components must be 0. Set the camera's Y position to 0.08 to better frame the planet.

There you go—our scene is ready to be rendered! Click the small “Play” button at the top center of the Unity editor. This will switch you to “Game” view, which lets you see exactly what your planet will look like when your game is actually running (at runtime).

The Play button lets you preview the game's runtime.

brasil/courses/blender_unity/unity/2_game_objects.txt · Dernière modification : de yann
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0