# [No coding] Using Components

Information
Step 1
In this lesson, we will try out various components to see what it does on an object!
Step 2
Create a new scene or stay on the current scene/project if you have Unity opened.
Step 3
In the Hierarchy create a plane, in the project panel create a black material and click n drag onto the plane.
Step 4
Create a cube slightly above the plane.
Step 5
Select the Main Camera, Look at the camera view and make sure the cube is visible.
Step 6
Step 7
Click play and you'll see that nothing happens yet.
Information
Step 8
Optional: Turn off 3D Icons and Grid lines in Gizmo if it's too hard to see the objects.
Step 9
Select the cube in the Hierarchy/Scene, in the inspector, add a component called Rigidbody.
Step 10
Now try clicking play, the cube will then have gravity. Next, stay in play mode, click on Scene, drag the cube up!
Step 11
Create a Sphere and put it next to the cube. Give that a rigidbody also, and disable both their gravities.
Step 12
Hit play and try to move the sphere into the cube and let got of the mouse.

Because there is no gravity, both objects move freely in space! Just like in outer space!

Step 13
This time enable Kinematic for the Cube. Click play, try "slowly" moving the sphere into the cube.

Kinematic objects are frozen in place and does not move but they do have collision.

Step 14
Disable all gravity and Kinematic on both object's Rigidbodies. And then add a Configureable Joint on the Sphere.
Step 15
There is a lot of settings here, don't worry we'll only use 4 of them. Click and drag the cube onto the connected Body.
Step 16
Click the triangle arrows on X,Y,Z drive to open them on this joint component of the sphere.
Step 17
With X,Y,Z Drive opened on this panel. Set all Position Spring to the value of 1.
Step 18
Now hit play and go to the scene mode, Try clicking and dragging the sphere away from the cube.

Just imagine them being connected by an invisible spring!

Step 19
Let's move onto a special render called the Trail Renderer! Delete both cube and sphere objects.
Step 20
Create a new sphere and attach a Trail Renderer component to it.
Step 21
Let's hit play, go to scene view and drag the sphere to see the trail.... Uh oh, it's pink! It's missing a material!
Step 22
Create a new material in the project panel, Name it TrailMat and make it any color you want.

I decided to make mines this color

Step 23
Go back to Trail Renderer for the sphere, Click the triangle arrow where it says Materials to open it.
Step 24
Click and drag TrailMat into where it says "Element 0"
Step 25
Click Play and check again if it's showing the right trail material.
Step 26
We notice that the trail is taking awhile to disappear. In the trail render, the time is in seconds. Change this to 0.3
Step 27
Click play and test again to see if the trail disappears after 0.3 seconds.
Planning
Step 28
Next we want to change the end of the trail to become more pointed instead of flat
Step 29
To do this, change the width with this curve. Right click at the end and then add key, then drag it down.
Step 30
Hit play and test your trail!
Challenge
Step 31
Shaders Challenge: Try changing the current material to just a lit up color instead of a metallic blue.
Step 32
Next we'll work on Constant force and Prefabs. On the same sphere, add a new component: "Constant Force"
Step 33
Make sure Gravity and Kinematic is Unchecked. And give this a constant force of 50 for x.
Step 34
Click play and see which direction this will go.
Information
Step 35
My camera might be a different position from yours. I need this to fly forward. If backward is x:50, forward is x:-50
Step 36
Make sure that the sphere is flying forward from your camera for the next steps of this lesson.
Step 37
Now that we have that working, we need more copies of it. We do this by saving "prefabs".

To save a prefab, click and drag an object from the Hierarchy to the Project. This will save a prefab with all the settings you've done on it.

Step 38
The fun part: Click play, and click & drag this prefab into the scene!
Challenge
Step 39
Give these spheres something to hit with!

Hint on creating multiple cubes: Create one, copy it, paste it. Move it over, copy both, past both, move it, and repeat.

Step 40
Lastly we'll try colliders. The current collider of the sphere is 0.5, let's try to increase this.
Step 41
Reminder: If you change an object in the scene, only that object is changed and not the prefab.

So whatever changes you made, you have to overwrite the prefab by clicking and dragging into it.

Step 42
Let's try launching just a "few" spheres this time.
Step 43
You are finished with this lesson! Click submit and go to the Challenges lesson!
[No coding] Using Components Info

Account

MVCode

Created By

Course:

[No coding] Unity Basics

Access Level

public

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.