Unity 101 - Carleton

[Pages:9]Unity 101

For Unity there are a huge variety of built in free engines. These are what are used to create 3D, 2D, VR style games, and many more. These are not only limited to just the game creation. They could also be used to design, create, and bring to life; animations, simulations of models, construction, etc.

Figure 1: the 2nd column contains the world environment with obstacles for our players Step 1 of building a game is to build the world/environment. This is the game field that our player(s) will be located, and how they will maneuver around; obstacles, enemies, etc. The world will determine the rest of the game, best part is that there can be multiple levels and scenes to this. With that we can transfer our controls' players and obstacles from level to level without any extra work.

Figure 2: the player environment

Step 2 is adding a player to our environment and providing them with maneuverability. Along with collision detection, building the score around the player and more.

Software Theory

Initial setup of Unity from home:

The program can be found on the this link. Following these steps:

1. Selecting Personal account -> Get Started 2. First-time User -> Start here 3. Agree and download 4. Launch and Agree to the license agreement 5. Install on the desired location on your hard drive 6. The setup options include:

a. The version of Unity you're installing, documentation, standard Assets, Microsoft Visual Studio Tools(optional, but recommended as it provides a very clean text editor), optional; if you are using Mac or Linux choose the build support

components.

Unity version will vary depending on the time of install 7. Click next, and the download process is done from there

Creating a project on Unity Once the setup is done we can launch the Unity Hub, the Hub holds the locations and the package of all the projects. Unity can be also be updated manually in the Installs tab, where the update can be selected. There are also several tutorials and community forums in the Hub that can be used for additional reference.

This is the layout of the Hub. Let's create our own project:

1. Click on New under the projects tab 2. A pop up will appear asking for what game design template you want to use? Enter a

name for your project and the location as to where you want to save it.

3. The initial load up make take some time but after that, we are ready to begin our first project

Unity UI tutorial

This is a default load out of Unity:

There are a bunch of tabs that can be seen, such as hierarchy, scene, game, inspector, etc. These work the same way like chrome tabs do. You can drag them around to lead the screen to your personal preference or switch between the tabs if you are on a small screen.

To focus on the main tabs, we have the following: 1) The Hierarchy:

In this tab we can add our objects in the game. These objects can be visible or non-visible paths for the game. When we want to create the environment layout we use the hierarchy to create our objects for the environment. A) Main Camera: in the hierarchy is used to show the views what the viewers perspective will be in the game. We Can add our player in the hierarchy and bridge the main camera to focus on the player only or we can code the main camera to follow our player throughout the game using vector offset(telling the camera how far away to stay from the player). B) Directional Light: we will not tamper with this to create our game, however if you wanted to adjust the angles that the light is bouncing off, we can rotate, pivot, or move the directional light around for that. This will show us different kinds of shadows, imagine it as the sun shining from a certain angle and having the shadows appear at different locations at the specific time of day. C) World/Player/Obstacles/Enemies: For the object portion of this, these can be added in the hierarchy section by clicking on the plus -> 3d object -> the desired shape you want. With

that we can add those portions into our game. To adjust the settings, size, portion of it, we need the inspector task bar.

2) The Inspector: This tab is very useful for adjusting our settings of our selected object in the hierarchy. In the inspector we have a few settings, along with more that can be added on.

A) Transform: The transform setting allows us to adjust the placement of the location, size, and angle. This feature is highly useful for our game development control settings. A short cut to controlling the transform keys are using the keyboard Q, W, E, R, T, & Y keys to control the settings of the object

B) Mesh Renderer: This setting is used to generate the object's texture and material, under the Material section, the label Element0, we can generate our own material in assets(covered soon) and drop that material in the element to give the object the texture we desire.

C) Box Collider: Is a form of a physic function. We can customize it with some code in the event we want to add an event that occurs if there is a collision between the objects.

D) Add Components: We can add elements here, such as scripts( C#) code that can provide the object with control of movement or trigger function(do this if something gets triggered in the game). We could add a physics rigid body function in there if we want to deal with kinematics or gravity components. There are so many components we can add. Those 2 are going to be our focus today.

3) Assets: These are supporting files for the game to add features, this could include a back ground, sample sound files, font packs, scenes, material for our objects, and several more.

A) Materials: One common use for assets is to create material for our game objects. This could be something like adding grass in our player field or just picking a solid colour. To do this, in the Assets tab -> Right click -> Create -> Material. We can name the material anything we want and select the colour in the setting. Do apply them to our objects, we would just drag it onto the inspector tab under Mesh Renderer -> Materials -> Elements.

4) Coding: Unity can be coded in either C# or JavaScript. Although Unity is has for support for C3, JavaScript could be used. For today, we will focus on C#.

With the visual studio package we added we have a cleaner layout. For the majority of the code we don't need to include System.Collection and System.Collections.Generic. Only requirement is the UnityEngine as it has the majority of our libraries that we use in the game. When you create a script in the assets tabs, if the script contains variables in it, we can lock those variables down to the object just by dragging them into the script portion of the inspector tool.

Activity See power point associated with this lesson to build an awesome game in 2 hours. If Participants are ahead of schedule they can also build more level's that are covered as extra near the end of the slide

Quick Tips Some of the common issues that were found when creating the game were:

1. The camera being positioned to close to the cube that when you play the game, the camera goes inside of the player and it gives it a 1st person perspective rather than a third person perspective. Fix: to angle the camera further back and position is slightly higher, optional: angle the camera facing down if you can see all the obstacles on the ground.

2. The player movement really varies between computer to computer. Thus, requiring adjustment of the forward and sideways force. This is why we adding a force vector relative to the time in our code. This ensures that the movement is based relative to the time. Otherwise, depending the on the processing power your computer has, some faster computers will have quicker player movement in them vs. A slower processing computer would have slower movement. Fix: ensure that Participants have adding the time component in their code for player movement.

3. When we code in Unity and refer to objects or components outside the scope of the code, we have to drag it into our code component. If this step is skipped, the game will not have our application applied to our code. Thus resulting in our code not "cooperating" with our game. It is important to drag the components of our code to our code in order to ensure we meet the criteria for our code. As it can be forgotten or skipped over sometimes.

a. for example, in our player movement code, we need to add our rigid body component to our code. To do this all we had to was to drag our rigid body component in the player movement scrip where we called it Rb for short. This would then be compatible with the code. Other Unity will not know what Rb is for.

Modifications

All participants will have relatively the same game in the end. However they can choose to do some steps differently, for example:

? They can choose different color for their object material or even choose a texture for their material. For example rather than have a green colored ground, they can add a grassy field ground if they desired.

? Participants can also adjust their forward and sideway force if they want to adjust the speed of the game. Greater the force, the quicker the player movement will be, and the difficulty of the game increases.

? Participants also can build their own level to their own design and level pattern. They could build their level with a gradual level that builds up difficulty or keep it consistent throughout the level.

? Participants may also choose to add a score screen that will account the distance they travel. This distance can be coded in and text added in their assets. The script code is attached in the lesson plan if they choose to do so.

? Finally, Participants on their free period can try to learn the on trigger function in unity to build their game for loading to the next level when they reach the end of their current level.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download