Particle Systems | Unity Tutorial

Do want to make a game that has explosions, smoke, or flames? To add effects like these in Unity, you can create particle systems. If you are a beginner and want to learn how to build virtual reality games, check out our Unity 3D course

Each particle in a particle system is a simple mesh. The effect of all the combined particles creates a moving object.

To create a particle system, right-click in the Hierarchy, and select “Particle System”. “Particle System” will appear in the Hierarchy. In the Scene, Particle System is represented as a trio of arrows with white clouds emerging from its center.

Select Particle System. In the Inspector, change its position to 0 0 0. In the Scene, you will see white clouds floating up from the position 0 0 0.

Moving a Particle System

You can move Particle System like any other object. To have the particle system be part of Cube, drag “Particle System” onto “Cube” in the Hierarchy.

Particle System’s position in the Scene does not change. However, its Y Position value in the Inspector changes to “1.5”. This occurs because the particle system’s position is now local. It is relative to the parent, Cube.

Cube is in the position 0 -1.5 0. Particle System is in the position 0 1.5 0. To position the particle system in the center of the cube, change Particle System’s Y Position value to 0.

Notice that there is a Particle Effect window in the Scene. With this window, you can pause, stop, and restart the particles’ movement.

Properties of a Particle System

In the Inspector, Start Delay refers to how long after the game’s beginning the particles will begin appearing. Start Lifetime refers to how long the particles will appear on the screen before disappearing. Set Start Lifetime to 1.

The higher the Start Speed, the faster the particles will move. Set Start Speed to 3. Change Start Color to yellow.

To demonstrate the Gravity Modifier, let’s rotate the particle system. Select the Rotating tool. Drag the green circle until Particle System’s Rotation values are approximately -30, -90, and -90.

Change the value of the Gravity Modifier to 1. You can increase the speed to 6. In the Scene, the particles will appear to be jumping out of the cube and falling to the floor.

Move Particle System around the Scene. No matter how quickly you move the game object around the screen, all the particles will move will your cursor.

However, if you change Simulation Space to “World” and move the game object, not all the particles will follow the object. The particles that have already fallen out of the object will continue falling in their trajectory.

In the Emission component, you can change the rate of particles that appear from the game object. Set Rate to 8. In the Shape component, you can form the shape that contains the particles. For instance, in the following screenshot, the particles are contained in a cone that has an angle of 6.1.

To learn more about particle systems, check out our Unity 3D course, where you build 30 virtual reality games!

Applying Physics to an Object | Unity Tutorial

For your VR game to feel real, its objects should move like they would in real life. In this tutorial, you will learn how to make your game objects respect the laws of physics. If you are a beginner and want to learn how to build virtual reality games, check out our Unity 3D course

Create a cube in the Hierarchy. We will apply physics to Cube so that it respects gravity. Move Cube up to a Y position of about 4.

By default, Cube does NOT respect gravity. Cube will remain suspended in the air – it won’t fall.

To prove it, press the Play button above the Scene window. The editor will darken. The Game window will open. The Play, Pause, and Forward buttons will become blue, meaning that the scene is live. The particles will jump and fall from Cube, but Cube will remain stationary.

Cube will not fall because we need to specifically tell Unity that we want Cube to respect the laws of physics. Press the Play button again to stop playing the game. In the Hierarchy, select Cube. We will give Cube a new component in the Inspector.

The Rigidbody Component

Click on the “Add Component” button at the bottom of the Inspector. Type “rigidbody” in the search bar. Select “Rigidbody”.

A Rigidbody component will appear in the Inspector. Rigidbody contains properties that pertain to physics. By creating this component for Cube, we have made Cube respect the laws of physics. Press the Play button. Cube will fall to the floor.

Currently, the particles fall to the left. Let’s have them fall from the bottom of the cube instead. Stop playing the scene. Select Particle System in the Hierarchy. In the Inspector, change the X Rotation value to 90. Press Play. The cube will fall, and particles will tumble out of it.

Stop playing the scene. Change the cube’s Rotation values to 45 45 40. Press Play to see the cube fall at an angle. When the cube hits the floor, it will rotate to sit on the floor.

Let’s make the cube collide with another object, such as a sphere. Stop playing the scene. In the Hierarchy, create a sphere. Position Sphere above the floor and under the cube, as in the following image. The sphere’s Position values should be about 0.2 5 0.14.

Press Play to see Cube fall and bounce against Sphere, as in the following image.

Stop playing the scene. Create two more spheres. Position them under Cube, as in the following image. To duplicate a sphere, press Control/Command+D. Alternatively, right-click, and select “Duplicate” in the Hierarchy.

Press Play to see Cube fall and tumble against the spheres.

Saving Your Project

In the Hierarchy, the file named “Untitled” contains the game’s elements. As evident in the following image, there is an asterisk beside “Untitled”. This means the file is not saved.

To save the scene, go to File > Save Scene. Give the file a name such as “Game.unity”. “Untitled” will change to “Game”. A file named “Game” will appear in the Assets folder.

To learn more about Unity, check out our Unity 3D course, where you build 30 virtual reality games!

Changing a Cube’s Color | Unity Tutorial

What’s a game without color? Color is so crucial in game development. Let’s learn how to change color in Unity. If you are a beginner and want to learn how to build virtual reality games, check out our Unity 3D course

Suppose we want to change the color of a cube in Unity’s Scene. Unity provides the default material “Default-Material” for the cube. To change the cube’s color, we need to create our own material.

Right-click in the Assets folder in the Project window. Select Create > Material.

As evident in the following image, a material will appear in Assets. Change the material’s name to “CubeMaterial”.

The Inspector will contain attributes of ColorMaterial. Click on the white rectangle in the “Main Maps” section under “CubeMaterial”. This will open a color picker, as you can see in the following image.

Choose a color such as red. The values of the sliders labeled “R”, “G,” “B”, and “A” will change. This is because every color can be represented as a combination of four values: red, green, blue, and alpha. The more red in a color, the higher the red value. The same goes for green and blue.

Alpha refers to a color’s transparency. A purely red color has red and alpha values of 255. Its blue and green values are 0. Give ColorMaterial a purely red color, as has been done in the following screenshot.

To assign Cube this red color, drag and drop ColorMaterial onto the cube in the Scene.

Alternatively, drag and drop ColorMaterial in the Element 0 field in the Cube’s Mesh Renderer component. The cube’s color will become red.

To learn more about Materials in Unity, check out our Unity 3D course, where you build 30 virtual reality games!

Learn JavaScript in 1 Hour! Book Release

All you need is 1 Hour.

Do you want to learn the foundations of computer programming? Are you tired of being bogged down by confusing jargon and complex descriptions? We have the book for you: Learn JavaScript in 1 Hour.

Learn JavaScript in 1 Hour is an easy-to-understand introduction to JavaScript. With this book, your website will be up-and-running in no time!

Important topics in web development are shown with examples that are easy to read. If you have a Mac computer, PC, or even a mobile device, you can follow along with the book’s examples on www.jsbin.com. JSBin is an editor that allows you to see your creations in real time.

Learn JavaScript in 1 Hour covers topics including:

Functions – Finally your website can do things! It’s not just a pretty face. Learn how to enable your site to perform tasks.

Variables – Integers, doubles, floats, characters, strings: these are all different types of variables. Variables are crucial to programming because they contain data. Learn about the different types and when you should use each one.

If Statements – If you read Learn JavaScript in 1 Hour, you will reach the section on conditionals. If statements run code IF a specific condition is met. With an if statement, you can test a value, run certain code only when you want to, and prevent your site from crashing!

If you want to learn how to give a website functionality, Learn JavaScript in 1 Hour can teach you the foundations of using JavaScript. Even if you have never coded before, you can follow along. For more books on tech topics, visit our Lulu shop.

Making a Cube | Unity Tutorial

To prototype a game in Unity, you can design a scene using primitives. To learn how to build 30 virtual reality games in Unity, check out our Unity 3D course! There are a number of primitives, or elements, that you can create in Unity, such as a cube.

Later, you can create more complex 3D elements in modeling programs, such as Blender. Then you can import the art into Unity.

Creating a 3D Primitive

To make a 3D element, right-click in the Hierarchy. A menu will appear containing listing game objects you can create. Clicking “Create Empty” would create a net game object, which has only a Transform component.

In the “3D Object” tab, there are names of three-dimensional shapes. Click on “Cube”, as in the next image.

“Cube” will appear in the Hierarchy. A cube will appear in the Scene, as you can see in the following image.

Cube’s Components

In the Inspector, there are many components for Cube. To position the cube in the center of the scene, change the X, Y, and Z Position values to 0.

If you change Cube’s X Scale value, Cube’s size will change in the X axis. Changing the Scale’s Y value makes the cube taller or shorter. The Z Scale value corresponds to the cube’s size in the depth axis, as evident in the following screenshot.

To change Cube’s scale visually, click on the fourth icon in the top left of Unity. Colored cubes will extend from Cube’s center. You can drag the cubes to change Cube’s size. If you click and drag the gray cube in the center of the cube object, Cube’s size will change in all three axes at once.

The Cube (Mesh Filter) component is the data for the 3D object that is rendered on the Scene. The Box Collider is used to process collisions.

The Mesh Renderer draws the cube. If you disable the Mesh Renderer by un-checking it, the cube will become invisible.

To learn more about the Mesh Renderer and Unity, check out our Unity 3D course, where you build 30 virtual reality games!