Appstore Blogs

Appstore Blogs

Want the latest?

appstore topics

Recent Posts

Archive

Showing posts tagged with Unity

April 03, 2018

Guest Blogger

game-jamming-blog-hero.png
Consider a playable build, no matter how simple, as a save point. It is a milestone along the way toward the finish line, and one that, if you were forced to abandon your game tomorrow, you would be able to return to.

[Read More]

February 28, 2018

Guest Blogger

game-jamming-blog-hero.png
Today, we are going to explore ways to create and iterate on the content assets of your game. This includes level designs, textures, shaders, sounds, music, particle systems, and anything else that makes up the look and feel of your game.

[Read More]

January 26, 2018

Guest Blogger

game-jamming-blog-hero.png
As you begin, remember that preparation and planning are key. During the iterative phase of game development, when your mock-up is still very malleable and subject to radical change, look for techniques that will help speed up your development time.

[Read More]

January 24, 2018

Chris Foley

unity_android_heroimage1.png
Developers targeting older Amazon Fire tablets (2012 and earlier) who are upgrading their Unity engines should be an aware of an important change in Unity’s Android support.

[Read More]

January 19, 2018

Emily Esposito Fulkerson

0119-gamejammingebook-image1.png
This book will empower you to make games fast, faster than you ever thought possible. It will teach you ultra-fast game jam workflows and uncover secret shortcuts to the finish line. Whether you’re a first-timer or a veteran gamdev, this book is for you.

[Read More]

January 03, 2018

Abdullah Hamed

unity_to_amazon.png

In this blog post, I'll cover the seven basic steps for bringing your Unity® app to the Amazon Appstore, quickly and easily.

[Read More]

July 16, 2014

Jesse Freeman

Introduction

For game developers, Fire’s Dynamic Perspective SDK opens up all kinds of new ways to let players interact with your game’s environment. The phone’s four dedicated cameras offer x, y and z data that you can use to determine where the player’s head is in relation to the device’s screen. This allows you to shift the perspective to reveal new angles on what would have otherwise been a flat image. Over the course of this tutorial, we will walk through how you can convert a simple splash screen to take advantage of a perspective camera, add Dynamic Perspective and create a parallax layering effect to give the scene more of an immersive feel. Before we get started, let’s take a quick look at how the splash screen appears before modifying it:

The above splash screen was built using Sprites in Unity 4.5 and setup with the Orthographic camera. You can download the original Unity project from HERE.

Getting Started

Once you have the project downloaded, open up the Splash scene inside of the Scenes folder so we can walk through how everything is set up.

Here you can see we have 5 sprites and our main camera. You’ll notice that our camera is set to Orthographic. We also have a black background to handle the outside areas around our artwork. Finally, each of our GameObjects has their own custom layer order so they render correctly.

If you run the project, you should see that our player moves up and down (appearing to float), and the start text blinks on and off. Inside of the Scripts folder you’ll find two scripts – “Blink” and “FloatEffect” that make this animation possible.

Now that you have a general understanding of how the project is set up, let’s start making the modifications to work with the perspective camera and lay down the foundation for adding in Fire’s Dynamic Perspective SDK.

Working with the Perspective Camera

Step 1. Select the Main Camera from the Hierarchy tab and change its Projection from Orthographic to Perspective.

You’ll see in the Camera Preview window that everything becomes smaller since the new perspective camera’s Field of View is set to the default value of 60.

Step 2. To start, let’s setup the game to run at the native resolution of the Fire phone (we’ll change this later). Go into the Game tab and select the resolution drop down. We’ll need to add a new resolution called 720p. It will look like this:

Step 3. Select the 720P resolution we just added and re-select the Main Camera so we can play with the Field of View until we find something we like.

Here I have set the Field of View to 30. Now the artwork is centered in the display correctly. Next, we’ll want to move things around a bit so that we add some depth to the scene.

Step 4. Go back into the Scene tab and change the following GameObject’s Z indexes like so:

GameObject

Z Position

BackgroundImage

1

BackgroundMask

-0.25

ClickToContinue

-0.5

Player

-1

Title

-0.5

You should now see there is a difference between what you see in the Scene view (Object A, Left) and what you see in the Game tab preview (Object B, Right) due to the perspective camera and the new Z positions we just setup.

In the game, the objects closer to the camera such as the player, the title, and the “click to start” text are now larger. It’s important to keep in mind that you won’t see these perspective differences in the Scene tab so it’s best to do our layout work in the Game tab.

Step 5. Now we can start testing out how our camera will react as it changes position and rotation in preparation for adding the Dynamic Perspective logic. We’ll run the game and be manually changing the values of the camera on the fly.

Here you can see we are testing by modifying the X position and X,Y rotation values of the Main Camera to simulate our scene being moved all the way to the right-hand side of the screen.

It’s also important to note that we will use this technique to determine our minimum and maximum camera values of the scene inside of Unity itself. This is not something I advise doing on the hardware because moving the phone while trying to test it distorts the view. Instead, I recommend you test all the measurements in Unity. Before we move on, let’s make a few corrections. We’ll want to alter the Main Camera’s Z position to move it closer to the graphics and we’ll need to readjust the Field of View as well.

Step 6. While in the Game tab, you can preview the changes you just made. Change the Main Camera’s Z position to -4.2 to bring the camera in closer, and reset the Field of View to 67.2. This will center the screen better and help give us a better effect later on when we add in Dynamic Perspective. You’ll want to play around with the camera based on you own needs to find the ideal zoom level as well as distortion when the camera rotates based on the head tracking position.

You’ll notice that the perspective is a lot more dramatic. Now when the user is moving their head or the phone as the game is tracking their head position. Widening the Field of View and moving the Camera closer to the objects in the scene will create a little more distortion at the far ends of the screen helping emphasize the effect.

Step 7. Let’s make sure we stop the game, permanently make the Position Z and Field of View changes, and save the scene.

Correcting Layout for Perspective

Step 8. While our GameObjects look OK in their current position, we should make a few adjustments to ensure they stay in place as the camera moves around. To get started, make the following modifications:

GameObject

X Position

Y Position

BackgroundImage

0.44

0

BackgroundMask

-0.35

-3.25

ClickToContinue

1.8

-1.57

Player

-1.15

0

Title

1.6

-1.05

Now all of our GameObjects are aligned a little higher on the screen to account for the shift in perspective. In a production game, you would want to detect if the Dynamic Perspective API is available via HeadTrackingReceiver.isAvailable() and possibly move the camera down a bit to compensate for the higher shift in perspective. You can just lower the camera since the code we’ll add will automatically reset the camera for you, but we don’t want to yet.

At this point you can run the game, play around with the X and Y Positions, and see the rotations of the camera. This will give you a sense for how everything will look when we add in our Dynamic Perspective logic.

Setting Up the Amazon Head Tracking Asset Package

Step 9. Now we are ready to import the libraries that will enable us to add Dynamic Perspective logic to our splash screen. You’ll find the Unity asset files in the Fire Phone SDK. From inside of Unity, select the Asset drop down and pick Import Package then Custom Package.

Step 10. You’ll need to find the Fire Phone SDK Unity Asset Package from the SDK folder. Once you select it, you’ll be presented with the following screen.

Here we are just going to import everything in the package. While we’ll only be focusing on the AmazonHeadTracking Plugin, you can also add Fire phone’s Motion Gestures to your game as well to add in support for those APIs. Once installed, you will now have a plugin folder along with the source code and sample scenes you’ll need to test out all of the features of the Fire hardware in Unity.

 

Creating the Dynamic Perspective Logic

Step 11. Let’s create a new script called HeadTrackingCamera. We’ll be using C# for the Script. Once you have the script open, add a few properties to the top of the class.

public float movementScale = 5.0f;

private Vector3 newPosition;

Step 12. The first property will represent the multiplier we will use on the X and Y position we’ll receive from the Dynamic Perspective API. The newPosition property will store the updated X and Y values for the camera after we do our calculations on the raw Dynamic Perspective data. Now add the following to the Start() method:

newPosition = transform.position;

This will save our initial camera position, and, moving forward, we will modify the X and Y properties of this vector instead of creating a new one from scratch.

Step 13. In our Update() method we are going to need to test that the Dynamic Perspective API is working and that we can access its data so add the following:

void Update() {
if (HeadTrackingReceiver.isAvailable &&
(HeadTrackingReceiver.lastEvent != null && HeadTrackingReceiver.lastEvent.isTracking)) {
}
}

Here you’ll see that we can talk directly to the HeadTrackingReciever class and access its data. We’ll be testing if it’s available, that the last event isn’t null and that it is still tracking the user. We want this to shut down if it stops tracking the user’s head.

Step 14. Now we can add our position calculations. Add the following inside of the new conditional we just created:

newPosition.x = Mathf.Clamp(HeadTrackingReceiver.lastEvent.x * movementScale, -.7f, .5f);
newPosition.y = Mathf.Clamp(HeadTrackingReceiver.lastEvent.y * movementScale, -.2f, .5f);
transform.position = newPosition;

We are getting the last event’s X and Y values, multiplying it by the movementScale we set up at the top of the class and using a Clamp() to keep it within a certain range of values. I have figured out the optimal values for you based on how far the scene will look when at the edges of the screen, which should help keep our scene in the camera’s view later on when we add the rotation to the camera.

Step 15. Before we test, we’ll need to add this script and the HeadTrackingReciever, which samples for new data every update during the Unity game loop, to the camera.

Step 16. At this point you are ready to test your game on the Fire device. Make sure Unity is set to Android as your platform and do a Build and Run of the game.

When you run this for the first time, you may be asked to locate your Android SDK. Just point Unity to the root of the SDK folder. You may also get the following error:

 

If you haven’t already done this, you’ll need to change the Bundle Identifier. From the Build Settings menu, select Player Settings, then change the default value of the Bundle Identifier.

Also, while you are in the Settings for Android tab, change the rotation to Landscape Left.

Finally, save your Android build to its own folder in your project.

Once you have the Scene deployed, you should now be able test out the Dynamic Perspective.

Step 17. We’ll also need to add a few properties to the class to make this work:

public float smooth = 1.0F;
public float tiltAngle = 2.0F;

Step 18. After running the project on the phone, you may notice that the parallax effect isn’t very dramatic. While it’s a cool effect, we can greatly enhance it by simply modifying the rotation of the camera in addition to changing its position. Below where we set the new transform value, let’s add this code:

float tiltAroundX = HeadTrackingReceiver.lastEvent.x * tiltAngle;
float tiltAroundY = HeadTrackingReceiver.lastEvent.y * tiltAngle;
Quaternion target = Quaternion.Euler(tiltAroundX, tiltAroundY, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);

Step 19. Now if you re-run the project on the phone, the effect will be a little more dramatic since we are also rotating the camera to match the shift in X and Y position.

Conclusion

At this point, you now have a reusable script you can apply to your camera that takes advantage of Dynamic Perspective in your Unity games. You don’t have to limit this to just the splash screen; I’ve been playing around with adding it to my main game scenes as well wherever I can take advantage of subtle shifts in perspective. When done correctly, the Dynamic Perspective effect is incredibly powerful. Use it to show off parts of the scene that may have normally been blocked by other items in the foreground, or just as a subtle way to add a little more depth to your Unity scenes. I also suggest checking out the Motion Gesture examples included in the Head Tracking Asset Package to add peek and tilt events to your game as well for menus and even to control elements in the game itself.

Now Is the Time to Submit Your Apps for Fire

Create immersive apps that respond to the way a customer holds, views and moves the phone. We have updated Appstore Developer Select, Amazon Mobile Ads API, and Amazon Testing Services with more incentives:

  • Appstore Developer Select: Optimize your apps for Fire phone and get enhanced merchandising and 500,000 Amazon Coins incentives for your customers. Get the details here.
  • Amazon Mobile Ads API: Developers earn $6 for every thousand interstitial ads displayed across any supported device in August and September (up to one million impressions per app per month) when they distribute their apps on Fire phones and send the first ad request from a qualified app. Get the details here.
  • Amazon App Testing Service: Most Android apps just work on Fire mobile devices. Test your app's compatibility in 90 seconds by dragging and dropping your Android APK into our testing tool. Sign up for a free developer account to test your app's look and feel on devices and get the results within 6 hours. Test your app now.

Now is the time to submit your apps and games! Apps that are submitted by July 18 and approved will be in the Amazon Appstore when Fire ships on July 25.

Fire Developer Resources:

May 20, 2014

Jesse Freeman

If you followed along from the first part of this series you should be up to speed on how the Unity IDE works. In this post we will dig deeper into the code side of things. I am a big fan of C#, and while Unity Script is useful, eventually you will need a little more flexibility in your code. So, to help you along, I thought it would be valuable to write a quick primer on working with C# in Unity, as well as some of the most common APIs you will be using when we build our game.

Picking a Code Editor

In order to code in Unity you will need to pick an external editor since Unity doesn’t have one built in. By default, Unity ships with MonoBuilder, but you can just as easily switch it out for something a little more robust, such as Visual Studio if you are doing your development on Windows. Simply go into the Edit > Preferences menu and change the path to the external editor.

Once you have picked an editor you like, you are ready to start coding. In this post, I will be showing the code from Visual Studio, but MonoDeveloper will work similarly to Visual Studio but on Windows and Mac.

Data Structures

C# is a strongly typed language and is very similar to Java or ActionScript 3. If you have some background in JavaScript, it should feel familiar as well. Let’s take a look at the basics of the language. To start with, we will look at variables and lists, which are the building blocks of any language. To make a variable, simply declare it, like so:

var name = “Jesse Freeman”;

While C# is a typed language, it supports type inference, meaning that when you declare a variable you don’t always have to define the type. There are a few primitive types you should know about:

string name = “Jesse Freeman”;
int age = 34;
bool alive = true;

When it comes to numbers, you should also understand more complex types, such as Float:

float speed = 4f;

Notice that we use the f suffix for our float. Floats are numbers that contain decimals and are used for more granular positioning within the game world, as well as in the built-in physics engine. Ints are useful for whole numbers where you don’t need to perform calculations that would generate fractions, such as a player’s health. You should always be aware when using Int, Float, or other number types because you may be forced to cast it to a specific type in order to perform the calculation and you may incur a performance penalty. Here is an example:

float example = (float)age * speed;

You can learn more about the different types in the C# reference docs at http://bit.ly/1bwLAKW. The next set of building blocks is Array and List. An Array is collection of multiple variables, usually of the same type.

var stringArray = new string[2];

In C#, Array are fixed meaning you can’t alter their length. You can modify its contents via their position in the Array itself. The position is an id, which represents a unique number for each location in the Array. In C#, arrays start at 0.:

stringArray[0] = “Jesse”;
stringArray[1] = “Freeman”;

You can access values in an Array by their index just like we modified it. Here is how I would create a string with my full name from the above Array:

var name = stringArray[0]+” “+stringArray[1];

Unity also supports Lists as part of the C# library. In order to use this, you will have to import its package (System.Collections.Generic) at the top of your script, which I will show you how to do later on. For now, here is an example of a list:

List<int> listOfInts;

This is what we would call a generic List. The term generic refers to a dynamic type we can assign at runtime. Generics are a core part of the language, and something you should get familiar with as you gain more experience coding in C#. In this example, we can create a list with a type of Int. Now this generic list can contain whole numbers. For performance, you will want to use lists over arrays when you don’t know the exact size of the data and expect to be adding or removing values at runtime. An Array by contrast has a set number of items you can have in it and shouldn’t attempt to modify the length at runtime.

The last data object I want to talk about is a vector. Unity makes use of a Vector3, but now with the addition of the 2D workflow, they now rely on Vector2D a lot more. Here are examples of both:

var v3 = new Vector3(0,0,0);
var v2 = new Vector2(0,0);

Vectors allow you to store 3D or, in this case, 2D points in space so you can access the value of x, y, and z from the vector. Here is an example:

Debug.Log(v3.x); // will output 0

One quick note is that you see I am calling Debug.Log. This will output the value to the console window.

This is similar to most other languages, such as JavaScript’s console.log and ActionScript’s trace. It’s also the first step in debugging your apps if you ever need to see the value of an object or property.

Classes

C# takes full advantage of classes, interfaces, and a host of other ways of packaging up code for reusability. Unity itself is built on a very easy-to-grasp composition system, which it favors over inheritance. Let’s look at how to make a simple class. Go to the Create menu and select a new script.

As you begin to create a new script, you will notice you can select from the three built-in languages. Select C# and call the script HelloWorld.

Unity will stub out the code you need for your class for you. Here is what it will look like:

using UnityEngine;
using System.Collections;

public class HelloWorld : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

As you can see, you won’t need to memorize how to create a class from scratch, so I will simply focus on two main parts of the script: the import block and the methods. By default, each new class extends from MonoBehavior. There are numerous methods you can take advantage of, but we’ll start with the first two: Start and Update.

Let’s go back to our previous example of a generic list. While this isn’t the traditional way of doing a Hello World example, I’ll be able to show off in a little more detail what it is like to import external libraries, create properties on a class, and output that to the console window. To start, look at the top of the class at the import statement and add the following:

using System.Collections.Generic;

Now, just before the Start method, we are going to add a property. Properties are variables that are scoped to the instance of the class itself. That is a fancy way of saying that anything inside a block of code will have access to its contents. Depending on how we declare the property, other classes will have access to it as well. C# supports private and public variable denotations. If you don’t declare one, it will automatically default to private. Add the following property above our Start method:

public List displayText;

Now, in our Start method, add the following:

displayText.Add("Hello");
displayText.Add("World");

Now we need a way to display this text. Add the following to the Update method:

Debug.Log(displayText[0] + “ “ + displayText[1]);

Here you can see we are using the Debug.Log method again, and we are accessing the first and second values of our list. It’s important to note that arrays and lists are 0 based in C# just like Java, AS3, and JS. Now we have a script that will output Hello World to the console tab on each frame, but we don’t have a place to put it. Go back to the Scene and select our camera. From here, scroll down to the bottom of the Inspector panel and select Add Component. Now select our HelloWorld script and it will attach itself to the camera.

Now, if you run the game and look at the Console tab, you will see Hello World outputted on each frame.

While this is a simple example, let’s do something a bit more interesting. Go back into your script and let’s have the camera scroll to the right. The camera is a GameObject just like any other primitive you add to the Scene via the Create menu. All of these GameObjects share some common properties, with position, size, and scale being just a few of them. Also, all of these GameObjects share the same API we are taking advantage of right now, which are the Start and Update methods. Let’s look at how we can programmatically move the camera. To get started, let’s add a new property called:

public float speed = 2f;

Next we’ll want to replace our Hello World Debug.Log call with the following:

transform.Translate(new Vector3(speed, 0, 0) * Time.deltaTime);

As you can see, we have taken the transform position property and are modifying it with a new Vector3 that contains our speed value and is multiplied by the Time.deltaTime. If you simply increased the x position by speed, you are not taking into account any slowdowns in the game itself. By using the delta between each frame, you are able to keep your movement consistent from frame to frame, regardless of dips in the frame rate. This isn’t a magical formula; all it means is that your GameObject will move at the desired distance over time. So if the frame rate drops, movement will look jerky but won’t slow down or speed up as the FPS naturally fluctuates based on other things going on in the game.

If you run the game, you will see the camera move. It will appear like the box that we created earlier is simply scrolling off the left side of the screen. Stop the game and take a look at the camera’s Inspector panel. If you scroll down to the script area, you will see we now have a new input field called Speed we can alter.

This is an important concept in Unity. Basically, any public property on a script can be edited from the IDE in the Inspector window. So, while it’s important to create default values for your properties, just know that you can alter those values on an instance-by-instance basis, and even temporarily at runtime when you are debugging. This is incredibly powerful and something we will be taking advantage of later on. Not only does this work with simple properties, such as Strings, Numbers, and Booleans, but it also works with collections, such as Arrays and Lists.

If you remember back to our first example, we had a list called displayText, which we also made public. You should see it in the Inspector panel as well, but the value is hidden. Simply click on the arrow next to its property name. You can even add new items to it by changing the Size value.

So, at this point, you should have a basic concept of how scripting works in Unity. Everything we covered here will be re-introduced in the following chapter. There is just one last thing I want to cover, which is how to think through scripts for GameObjects.

Composition over Inheritance

If you come from a traditional computer science background or have worked with other object-oriented programming languages before, you may be familiar with the argument on composition over inheritance. One of the cornerstones of OOP languages is the concept of polymorphism. While inheritance plays a large role in game development, Unity strives for the use of composition as much as possible. I consider scripting in Unity to follow the decorator and component design pattern. Each script adds additional functionality to your GameObject, but they are mostly self-contained. While some scripts rely on others to function, as we will see in the game we end up building, we really strive to create small, reusable blocks of code that can be applied to multiple GameObjects. When put together, each of these smaller scripts build up to a greater set of logic that builds up the functionality of each GameObject. While inheritance is possible, I strongly recommend thinking through composition as a means to not only create more modular, self-contained code but to also separate and encapsulate independent game logic. This kind of thinking is critical when it comes to grasping the true power of creating scripts in Unity.

Wrapping Up

By now I am sure you are itching to get into more coding, so start playing around with some of the great tutorials out there on Unity. We’ll continue to add new posts about Unity, especially with working with the new 2D workflow, over the next few months so make sure you keep checking back.

Also, don’t forget that to checkout Amazon’s GameCircle plug-in for Unity to help you integrate cross-platform leaderboards, achievements, and game data synchronization. The plug-in works on iOS, Android, and Fire OS plus with the built-in Whispersync for Games component you can back up all of your user’s game data to the cloud across all three platforms. You can now download it from the Scripting/Integration section of the Unity Asset Store.

Additional Resources

-Jesse Freeman (@JesseFreeman)

 

May 19, 2014

Jesse Freeman

Unity is the de facto game framework and IDE for a lot of the success stories you read about on multiple platforms. The IDE is very polished and easy to use. As Unity was previously just a 3D tool, there was a certain level of knowledge you needed before getting started. Now with the addition of an all-new 2D workflow, things have gotten a lot easier for game developers looking to build simple, non-3d games. In this post we’ll take a look at how the Unity IDE works for 2D game development.

Over the next few sections, we will take a look at the IDE itself and how to navigate around it and GameObject, which are the building blocks of your game. There are a lot of resources out there on Unity, but for people who have never opened it up before, this post will help get you acquainted with the basics in the IDE.

Creating a New Project

When you create a new project in Unity, you will see the following wizard:

As you can see, you are given an option to set the location of where you want to create your project, as well as packages you can include when it is created. The final thing to note, which is new in Unity 4.3, is the 2D setup tab at the bottom of the window.

By setting this to 2D, your project will automatically be configured for 2D game development. Let’s create a project called SPMS2D and toggle 2D.

Once you create your project, you will go into the editor and see the “Welcome To Unity” screen. I highly suggest going through some of the videos to learn more about how Unity works and get a sense for the workflow. Most of it is geared toward 3D, but it still applies to the stuff we will go over in this blog. I also suggest checking out the forums since there is a lot of really good information on there that can help you out when you get stuck as you are getting started learning Unity.

How to Use the IDE

At first, Unity may be a little intimidating, but I personally find that the new 2D mode actually simplifies things greatly. Here is a high-level overview of the IDE. When you first open up a project in Unity you will see the following window.

Let’s go over each section of the IDE’s window by window. First, we’ll start with the main area.

This is where you will lay out objects, preview and test your game, and also work on animations and other visual-based activities. As you can see from the tabs, the Scene and Game tabs are already open. Below the tabs, you will see a few quick-access menus. The most important is the 2D toggle, which is already activated. By unchecking it, you will go back into Unity’s native 3D view.

I’m not going to go into the 3D navigation tools since we will be focusing on 2D instead so let’s look at the Hierarchy panel.

As you add stuff to your scene, you will be able to see and access them from here. For now there is a single object, which is the camera. Also, you have access to a Create shortcut menu, which we will be using a little later on. The same options can be accessed in the IDE’s top menus as well.

While you are looking at the Hierarchy tab, select Camera so we can discuss the Inspector panel next.

Here you can see all of the properties that make up the camera for our game. Unity does a great job of visualizing all the parts that can be configured on each object in your Scene. The Inspector panel not only allows you to modify values, even on the fly while the game is running, but it also lets you add additional functionality onto any GameObject via the Add Component button.

We will get into some of these components a little later on, especially scripts, which will make up a huge part of your coding experience. For now, it’s important to note that a GameObject is anything in the game itself and may be the camera, the player, or even more complex objects like levels, UI or even utilities we build to help us visualize elements in the game. Next up is the Project tab.

Think of this as a view into the project folder itself. To help you better understand it, go to where you created your project on your system and open it up.

As you can see, in addition to all of the additional files that make up the Unity game project, you will see there is an Assets folder. This becomes your default location for everything you put in your game. Here we will store artwork, sounds, scripts, and prefabs, which are reusable pre-configured GameObjects.

The final two things I want to cover may be self-explanatory but are always useful to review. In the upper-left corner you have a set of controls to help you navigate the Scene window.

While these tools are mostly focused around navigating a scene in 3D mode, they don’t have much use in 2D mode. When working in 2D the tool you will use the most is the Hand to simply drag the screen around on the x- and y-axis.

The other set of controls handles playback and allows you to test the game.

Simply hit Play to start the testing in the Game tab.

You will also notice the Pause and Step-Forward buttons. These are incredibly helpful in allowing you to move through the game frame by frame to see what is going on. You can also go back to the Scene tab while playing the game and modify values of GameObjects at runtime. It’s important to note that any changes you make in the Inspector panel while running the game don’t get saved; it simply allows you to try things on the fly without having to stop testing, make a change, and recompile.

GameObjects

Before we get into the coding and specific 2D tools, I wanted to provide some information about GameObjects, which are the building blocks of a Unity game. As you begin to flesh things out, you will start by creating these GameObjects in the Scene. Some of them will represent your Player, bad guys, and level while others will make up utilities and Gizmos, which we will learn about later on, to help you manage other GameObjects in the game.

To get you used to working with GameObjects, let’s just create a simple cube and position it in our Scene. Go to the GameObject menu at the top, or the Create menu from the Hierarchy panel, and select Cube.

Now, if you check your Hierarchy panel, you will see the cube and the camera. Select the cube to bring it up in the Inspector panel.

If you run your game now, you will not see the cube. Likewise, you can click on the camera to preview the Scene without even hitting Run.

We can fix this by adjusting the cube’s z-axis in the Inspector window to 0.

Now, if you run the game, you will see the cube.

Notice that we still have the Inspector panel open with the cube. You can continue to play with the cube’s properties while the game runs. If you roll over any number property, you will see the cursor change into a two-sided arrow, and you can use that to click and drag the value in the field up and down. Give it a try with the x and y properties of the cube. Since we are in 2D mode, modifying the z-axis will not do anything eventful. When you stop running the game, all of the values will reset themselves.

Wrapping Up

At this point you sound be familiar with the Unity IDE and the new settings for working in 2D. In the next post I’ll cover a primer on C# in Unity and how to start making basic scripts for your own games. Stay tuned!

Also, don’t forget that to checkout Amazon’s GameCircle plug-in for Unity to help you integrate cross-platform leaderboards, achievements, and game data synchronization. The plug-in works on iOS, Android, and Fire OS plus with the built-in Whispersync for Games component you can back up all of your user’s game data to the cloud across all three platforms. You can now download it from the Scripting/Integration section of the Unity Asset Store.

Introduction to Unity Part 2: Learning C#

- Jesse Freeman (@jessefreeman)

 

Want the latest?

appstore topics

Recent Posts

Archive