#programmingdevil
Explore tagged Tumblr posts
Text
Post 3 -Tutorials Part 2
Hello everyone and welcome to this week’s blog post. Today we will be continuing with the basic tutorials of how to use Unity.
Tumblr media
First, we will be looking at Tweaking Components, so go on and start it up.
Once Unity loads up, we will start with learning how to set values to components. Now let us enter Play mode and see what the game level has in store for us.
Tumblr media
As we can see, when our player steps on the red square, an enemy NPC comes rushing out. He is going so fast that our player can’t get through. Let’s do something about that. Exit Play Mode and we’ll take care of the trash.
Tumblr media
Go to the Hierarchy Window and select the Enemy game object. From there Inspector window will open with the Enemy’s info. Here we are looking for it’s speed attribute in the NavMeshAgent component. This component is part of Unity’s built in AI system. When a game object has the NavMeshAgent component attached to it, it will use AI to interact with it’s environment. In the speed attribute set the speed to 1. This will allow us to change how fast the object goes around the environment, isn’t that useful.
Tumblr media
Now let’s go into Play mode and try to get past the enemy now.
Tumblr media
Great. The enemy is so slow we can go right past them without worry. However, now the door to the goal blocked a by a fast closing door, which is not very epic gamer style. Exit Play mode and let’s fix it.
Tumblr media
Go back to the Hierarchy window and select the Automatic Doors Game Object and go to the Inspector window.
Tumblr media
From there, we will be looking for the Time Until Close attribute which is under the Door component. This component is not a built-in component of Unity, it is a script made in code, which is something we will be doing in the next post. For now, set the Time Until Close attribute to 10 and enter Play Mode to see the results.
Tumblr media
There we go. We made it to the goal, which is indeed an Epic Gamer moment.
Tumblr media
With that the Tweaking Components tutorial is done. Next, we will do the final basic tutorial of Prefab Power. The excitement is overwhelming, so let’s jump right in.
A Prefab is a file that contains a Game Object that works in the way it is supposed to. By creating a Prefab, we can take that fully functioning Game Object and make copies of it. Before we get into how to make a Prefab, let’s enter Play Mode and see what we have to work with.
Tumblr media
When we move our character to green triangle, we see the door object open to the goal. However, we cannot get over to the goal. With no ability to jump, we have to figure out a way to get through. Exit Play Mode and let’s do just that.
Tumblr media
This time we will be going to the Project window. The Project window shows all the files that are used in the game, which are called assets, and let me tell you we got some nice assets. Anyway, assets cover things like models, audio, scripts and so on. Here in this window is where we will find the Prefabs. Now select the ramp Prefab.
From the Project window, we can drag a copy of the Prefab into our Scene view or the Hierarchy window. Doing this creates an instance of the Prefab. Now let’s try just that.
Tumblr media
As you can see, by dragging the ramp Prefab into the empty space of the Hierarchy window, it placed it right into the Scene View for us. Now our character can gain the high ground over his former friend. *cough* Star Wars reference. Anyway, let us enter Play Mode and get the high ground.
Tumblr media
We did it, we have the high ground, but another obstacle blocks our way. Looks we need another Prefab to block the laser. Exit Play Mode and let’s get down to business to defeat the Huns. *cough* Mulan reference.
Tumblr media
Go back to the Project window and drag the PushableBox Prefab into the Hierarchy view. You’ll notice that the Prefab is not in the place we need it to be, so let’s fix that. For that we will be adjusting the values in the Transform component of the box. All Game Objects have a Transform component, which holds data about where the object is in the scene, how it is scaled, and how it is rotated.
Tumblr media
In the Inspector window, go to the boxes position attribute and set the X value to -2.
Tumblr media
From there we can see that the box moved to the right a little. Now let’s move it in the Y direction.
Tumblr media Tumblr media
Change the Y value to be 2.5 and watch what happens. Now the box is floating in the air. Creepy right, well there is one more direction for this box to move and that is in the Z direction.
Tumblr media Tumblr media
Now replace the Z value with 10 and the box will be in place to move it move it. *cough* Madagascar reference. Gosh guys I’m sorry about my coughs, must be coming down with something. Anyway, everything is set up, so let’s dive right into Play Mode.
Tumblr media
Alright, we made it to the goal. Epic Gamer Moment achieved.
I hope this post was helpful in teaching about setting values to components and using Prefabs to get things done. Next weeks post is where we will be making some Unity scripts with C# in Visual Studio. I hope your looking forward to it. Until then I am the Programming Devil and May Your Heart Be Your Guiding Key.
0 notes