Introduction: Spinning Earth - Beginners Unity Project

App Development has never been easier. Today, and the click of a mouse, one can create a new app.

So here, I have a simple instructable for creating an app with Unity 5.

The game itself is not the star, but the method is. I created a simple spinning earth, but I suggest coming up with something cool and innovative. Unity has awesome tutorials for the same.

If you liked the instructable, please vote!

Step 1: Unity

For this instructable, you need Unity 5, the personal edition for which is FREE. All scripts are made in C#. C# is a programming language, which I will use to add scripts. A script is a piece of code you add to an object to make it follow your instructions..

I will walk you through making a simple game in which you can spin the Earth.

This tutorial is meant for the ABSOLUTE beginner, who has no idea about programming

Check the video to see the game-play.

Step 2: Introducing Unity - Step 1

When you launch unity, you will see a screen where a you can give your project name, location, 2D/3D etc.

Select the 3D option. I will call my project 'Spin.' Click on create. The setup is shown in the picture.

The menu that opens in the side is called the inspector, and it allows us to edit and view the attributes of various components.

Let me give you a quick overview on the general controls. After you launch Unity you will see the window in the picture. '#Scene' is where you actually edit the different components, and 'Game' is what the app would look like while running. Switch to scene.

To Zoom in, use scroll up or down.

To rotate the view, press Ctrl and move the cursor.

To move the view, press Ctrl + Alt and move the cursor.

The Console is really useful for finding errors in your game and debugging.

Project is where all the different parts AKA Assets of the game are shown.

Lets get started now.

Step 3: Making Our Sphere - Step 2

Next we will create a GameObject. All unity games are made up GameObjects, which is basically everything that we can control, and is on the scene. This includes all shapes, cameras and lights. Go to the left menu where all GameObjects are listed and delete 'Directional Light'.

Next, go to the 'GameObject' in the Menu Bar, go to 3D Object < Sphere

Now check the right of the screen, and in the inspector, change the position values of the sphere. Change position in X axis, Y axis and Z axis to 0.

If we go to 'Game' we will see our camera view is terrible. Time to change that.

Before we proceed, it would be best to save our scene. Press Ctrl + S, and I named it instructables.


Step 4: Adjusting Camera - Step 3

At this point, our cube is in a really good position, but our camera needs some adjustment.

We are going to move and tilt our camera, to give a better 3D effect.

Let the Position values for x and y be 0, but make the Z value to -1.5, to put some distance between the sphere and the camera. Next we will add a new light, to make the scene visually appealing.

Go to GameObject > Lights > Spotlight.

Next we will arrange our spotlight in such a way that the sphere gets a nice 3D effect.

In the inspector, for position, change the X value to 1.5 and Z value to -2.

Next for rotation, we need to rotate our light to give a shadow. For that set, the value for Y to 320.

The light is well set, but is too dim. Below the inspector, in the light menu, we can find the intensity slider. Set it to 1.8.

After every step, save the scene to preserve your changes.

Step 5: The Script - Step 4

This is the part that makes the project tick. A script is a set of guidelines written in a specific language. In this case, the programming language used is C#. Adding a script to our sphere, will make it rotate.

To begin, right click in the assets screen in the bottom, and go to Create > C# Script.

I named the script 'Spin'. It is the only script we will be using.

Double click on the script, and it will open in MonoDevelope, and you will see some lines of code are already there.

There are also numbers on the left. They number the lines of the script, and are not read as code. Note that most lines, in which instructions are given, end with a semicolon. ( ; )

First, I shall paste the script, then I will explain it line-by-line.

using UnityEngine;

using System.Collections;

public class Spin : MonoBehaviour{ public float speed; void Update () { transform.Rotate(Vector3.up,speed * Time.deltaTime); } }

Let us start.

Ignore lines 1 - 6, as they are essential in most Unity scripts.
Assuming you know nothing about programming, I will not explain, as this involves 'Inheritance'.

Step 6: Script Explained - Step 5

I will start explaining from the 7th line, as explained before. I will also ignore the curly braces, for your convenience.

public float speed; // This creates a variable called speed which can be accesed in Unity, i.e. it is public. This variable is a data type called float, which is basically decimal numbers.

void Update () // This tells Unity to run this code after every frame. This implies it is perpetually running.

transform.Rotate(Vector3.up,speed * Time.deltaTime);

This is the most important part. transform.rotate tells it to change or transform its rotation, in the axis of Vector3.up.

Vector3 refers to a 3D plane, and up refers to Y-axis. So, it tells unity to rotate our sphere in the Y-axis.

It tells it to rotate by the distance of our variable speed multiplied by Time.deltaTime. Time.deltaTime, is the time since the previous frame. The framerate constantly changes, so if the distance to be covered remains the same, the sphere would constantly change its speed. Remeber speed = distance / time => distance = speed x time.

So if the time since the last frame changes, the distance to be covered will increase to keep up with the framerate, and maintain a constant speed. That's all.

Step 7: Making Our Earth - Step 6

Now, we must add our script to the sphere. To do so, drag the script from the Assets menu in the bottom to the sphere on the scene. That's all. Now, we need to set a value for our variable speed. To do so, click on the sphere, and go down into script in the inspector. Now change speed, which is 0, to 20. You can choose your own value.

Play the Game!!! You will see the sphere rotate, but it doesn't look too cool. To do that, we need to add a new texture onto the sphere, to make it look like one.

A texture is an image you add to an object. A material is a set of textures, which you add to an object, and can even give a 3D effect. To start off with, create a new material, and name it Standard. We do this, in case we want our original sphere. Next, download the texture of the Earth I have uploaded, and drag it into Unity. It will automatically become a texture. Next, drag it onto the image. A new folder called 'Materials' will be created.

Materials give color and vibrance to objects. Textures are simple images. When we add a texture to an object, what is added is actually a material, that is automatically created.

You will see our Earth is shining. To stop that, we need to adjust the material created, in the newly formed folder. Click on Earth.mat(which is the only material in there). In the inspector, adjust the smoothness. Make it 0.

When you play the game, you will see the Earth rotate. Next we will add a Skybox, and finish up.

Step 8: Step 7 - Finishing Up

Next, we will make and add a Skybox. A Skybox is unity's version of a 3D background. To do this, download the image of stars I have uploaded.

Next, add it to unity as a texture, by dragging and dropping. Textures are simple images, as I said before. They make up other visual assets, Skyboxes being one of them.

So, go to Create > New Material. Name it 'stars'. Now, in the inspector, you will see, a drop down menu called 'Shaders'. Select Skybox > 6 sided.

In the inspector, a series of blank tiles will appear. This is where we insert our texture. Insert in each tile.

You have made the skybox. Next, we will add it to the camera. Click on the camera, go to Add Component > Rendering > Skybox. Drag and drop 'stars', our new skybox.

For neatness sake so that you and others can understand, make a folder called 'Textures'. Put both textures into it.

Step 9: Building and Running

Go to File > Build and Run, and click on build.

You will be asked to give a name for your program. I called mine SpinningCube. After this, go to the place where you saved the program and double click. Play the simple game you created!!!

If you liked this instructable, please vote, and comment.


dr_hazrd made it! (author)2016-03-09

Works great, very good for a beginner to Unity.

2016-03-09 (1).png2016-03-09.png
gsmr (author)2015-07-02

Thank you very much. I built it and learned many things

makeosaurus (author)2015-06-02

Where is the texture that you uploaded???

adithyashok (author)makeosaurus2015-06-11

This is the one - step 7


About This Instructable




Bio: Simplicity is the ultimate sophistication.
More by adithyashok:Arduino Random Music GeneratorSpinning Earth - Beginners Unity Project Easy Designs - Turtle Graphics Python
Add instructable to: