All posts in "C#"

Building Flappy Bird #1 – Unity Intro

Building Flappy Bird in Unity

Unity is a great engine, but like all game engines it has a little learning curve.  This tutorial is designed to take you through the entire process of building a 2D game in Unity that will run on the web, pc/mac, and mobile.  By the time you complete this project, you’ll understand:

  • The different areas of the Unity editor
  • Importing Art
  • Using the Physics system
  • Handling Input
  • Writing a little code (even if you’ve never written code before)

Let’s get started!

Importing the Art Package

In the editor, click Assets, Import Package, Custom Package

Importing a Unity Package

Select Assets->Import Package->Custom Package…

Browse to the Art assets package.  If you don’t have it, you can download it by clicking here.

Import package file list shows of all the files in the package

Import Package File List

You’ll be presented with a file list dialog.  This dialog allows you to select which files in the package you want to import.  By default, all files will be selected.

For now, click “Import”.

Next, focus your attention on the Hierarchy section of the editor.  It should be in the top left corner and contain a single GameObject named “Main Camera”

Hierarchy With Main Camera

Hierarchy With Main Camera

Select the Main Camera by clicking on it.

Hierarchy With Main Camera-Selected

Hierarchy With Main Camera-Selected

Selected GameObjects in your Hierarchy will show blue.  You can select any number of GameObjects at the same time.  For now though, we only have one available to us, so let’s look over to the other side.

Inspector View of "MainCamera"

Inspector View of “MainCamera”

On the right we have the Inspector area.  Here you can see or inspect details about your selected GameObjects.  Notice that the inspector shows 5 components because we’ve selected the default camera object Unity creates for us.   The 2 components you care about today are the Transform and the Camera.

Transform

EVERY GameObject in Unity has a Transform.  The transform controls the objects Position, Rotation, and Scale.

  • Position - The location of the object in the world or relative to it's parent.
  • Rotation - The direction the object is facing.
  • Scale - The size of the object.

Camera

This component allows our game to render.  This is the area we want to modify now.

First, try adjusting the “Background” value and notice how the background changes in the Game View (located in the center) or the Camera Preview.

To change the background, just click on the area showing the current color in the inspector.  The default is blue.

Color Picker

Color Picker

Once you’ve found a water color you like, you need to make sure the Camera Perspective is set to Orthographic.  (It should be by default, but we need to make sure)

Project View

It’s time to put something in our game.  Look to the bottom of your editor where you’ll see the Project area.

Project View

Project View

Browse to the art folder and select the Fish

Project View - Art Folder

Project View – Art Folder

Drag the Fish to the Hierarchy.

You should see the fish in your Hierarchy and in your Scene or Game View.

You can toggle between the 2 views using the tabs, or drag them out to separate them

Scene View Fish

Scene View Fish

Game View Fish

Game View Fish

Play Mode

Now, I want you to hit the Play button and watch what happens!

Game Play Button

Game Play Button

If you’ve followed along so far, nothing should have happened.  The Game View will automatically focus, but nothing should be moving.

Let’s make something happen…

With the Fish selected, hop over to the Inspector.

Click the big Add Component button.

Start typing and find the RigidBody2D.

You can alternatively browse to it under Physics2D.

 

Inspector Add Component

Inspector Add Component

The RigidBody2D component will make our GameObject (the Fish in this instance) interact with the games physics system.  One of those interactions is gravity…

Inspector RigidBody2D

Inspector RigidBody2D

Let’s Play

First, I want you to think for a second.  When you hit “Play” what do you expect will happen?  Say it to yourself, then hit the button and see if you’re right.

If you thought the fish would fall, great.  If not, don’t worry about it.  Because our fish has a RigidBody, it uses gravity (unless Gravity Scale is set to 0).  If there are no other forces acting on the object, the RigidBody will make it fall straight down.

In Part 2, we’ll start handling input and adding some additional force to keep the fish from falling away.

Continue To: Part 2 – Let’s Code!

 

Sign up here to be automatically notified about new posts


Continue reading >
Share

GIT – You should be using it

You should be using GIT

If you’ve been using source control, but haven’t made the change to git yet, let me try to convince you.  I first heard about git a few years ago.  It sounded interesting at the time, but my source control was working fine (or so I thought), so I didn’t pay too much attention.  Around 4yrs ago, I started a new project and had to pick a source control system.  One of the options we tried out was git.  Like most people, I searched google, read a bit of the docs, then hopped into the command line.  It was a disaster….

I’ve used command lines since the C64 days, can easily handle dos, powershell, and USED to be good with with linux.  That said, I’ve been primarily developing on windows, building games, websites and apps since the 90’s.  Using git via the command line felt un-intuitive and confusing.  Combining that with a new set of definitions for commands made it more confusing.  All this combined into the perfect storm of confusion.

Around 2 years ago I attended a few “Intro to Git” talks that explained the basics.  They always covered how git works and how to get around the command line.  They’d occasionally touch on the fact that visual tools existed, but they’d  focus on the command line because people who love git enough to do talks on it, love command lines.

The first thing I want to say if you’ve been avoiding git because it seems complicated/confusing, ignore the command line.  You can learn to use it later.  For now, grab one of the good graphical tools and get a bit of experience with git.  My preferred git tool is SourceTree.

Graphical tools have existed for every other source control system, so you may still need some more convincing.  The typical git pitch mentions things like offline commits & easy branching.  I won’t be covering those today.  Instead, I’ll focus on 4 points where git excels which I think may be more convincing.

#1. No file locking / read-only files

This may not be an issue for everyone, but if you’ve been a long time perforce user then you’ve fought with read-only files.  If you also happen to use Unity3D, you’ve realized just how terrible it can be.  With git, your files will no-longer be locked, read-only, or need to be checked out before you can work.

#2. Partial file commits

This one alone may be enough to convert some people.  Before switching to git, I can’t count the # of times where I was working on a feature, but needed to make a quick minor fix.  Before git, I’d stash my changes to the file in question, make the fix, and hope everything still built.  Then I’d commit, un-stash, and hope I didn’t mess up my previous work.

Git offers the perfect solution to this.  Partial commits.  If you’re using source tree, you can see just how easy it is in the image below. SourceTree - Free GIT GUI It will find the different areas of your file that have changed, and you just choose the part(s) you want to stage for commit.  You can simply commit what you want, and leave out everything else you’ve been working on.

 

#3. Commit changes without pushing them

You can commit, without pushing out your changes to anyone else.  If you’re still working on a feature, not sure about your code, or you’re just afraid to break an upcoming release, you can still commit.  Until you PUSH, your code is only committed locally.  You can roll back your changes, modify them, etc, without anyone else having access to the code until you’re ready.   It’s liberating…

#4. Finding changes is EASY

I can’t speak for all version control systems, but in many, finding your changes can be a pain.  Some systems like P4 require you or a plugin to specify each file (there are ways to find them, but they’re a pain too).  With git, it looks at the file system and sees your changes every time.  In the graphical tools, you get a nice easy view of all your changed files where you can choose which ones (or parts) to stage for commit.

There are of course many other reasons to use git.  It’s taken over as the primary source control system because it’s better than the competition.  I’m happy to have made the switch, and can’t imagine ever going back.  I hope I’ve convinced you as well.

Continue reading >
Share

SoCal Code Camp – L.A. (Nov 14th & 15th)

The summer session of SoCal Code Camp is coming up soon.

If you’re in the area, come check out my talks.

Intro to Unity Part I – 2D Games

In this session we’ll build a clone of a popular 2D mobile game in under an hour.  You’ll be introduced to the basics of the Unity3D engine and editor.  We’ll cover 2d physics & collisions, sprites, input, movement, and more.  By the end of the session we’ll build the working game to an android device.  After the session you should be able to recreate the basics of a few popular games.

Intro to Unity Part II – 3D & VR

The final session in this series is all about 3D game development and Virtual Reality.  Here, we’ll cover the differences between 2D & 3D games.  We’ll import some assets, setup animations, launch baseballs, then turn it into a VR experience.  After the session, you’ll be able to try out the virtual world we’ve built on the GearVR.

Continue reading >
Share

Another great code camp

Yesterday was my first time attending the Seattle Code Camp.  It was a great event and I had a great time meeting new developers and learning.  The organizers did a great job setting it up and keeping everything running smooth.

Some of the stuff I learned:

  • MVC tag helpers are pretty amazing and I’ll be using them next time I build a webpage
  • SQL Unit tests are easy and there’s no excuse for not using them (if you haven’t checked these out and work with a database, do it now)

If you didn’t make it this year, you should definitely attend the next one.  And if you’re in SoCal (or really like to fly), come check out the next SoCal Code Camp in LA.

 

If any attendees to my sessions have questions, please toss me an email jasonweimann@gmail.com

Continue reading >
Share

Seattle Code Camp – Sept 12th 2015

By Jason Weimann / September 2, 2015

I’ll be giving two talks at the upcoming Seattle Code Camp. If you’re in the area, come by and check out the code camp. It’s free and always a lot of fun.

These talks are aimed at developers who’ve never done any game development or maybe tinkered around a bit here and there.  The code is all in C# (though you can do it all in JavaScript too), and you’ll be surprised just how simple it is.

Get the info and pre-register here

Intro To Unity I – 2D Games [2:15 PM-3:15 PM]

In this session we’ll build a clone of a popular 2D mobile game in under an hour. You’ll be introduced to the basics of the Unity3D engine and editor. We’ll cover 2d physics & collisions, sprites, input, movement, and more. By the end of the session we’ll build the working game to an android device. After the session you should be able to recreate the basics of a few popular games.

Intro to Unity II – 3D & VR Games [3:30 PM-4:30 PM]

The final session in this series is all about 3D game development and Virtual Reality. Here, we’ll cover the differences between 2D & 3D games. We’ll build a softball batting game then turn it into a VR experience. After the session, you’ll be able to try out the virtual world we’ve built on the GearVR.

If you’d like to get more info or slides, just sign up for my mailing list.

Continue reading >
Share

SoCal Code Camp – San Diego

The summer SoCal Code Camp is just one week away and I’ve just finished preparing my 3rd talk.  If you’re in the San Diego area and interested in code or game development, it’s a great free event you should register for HERE.

My talks start Saturday June 28th at 12:15 PM.  I’ll run through a wide range of topics introducing you to 2D, 3D, and Virtual Reality development.  We’ll start with 2D games by building a flappy bird clone.  Next we move on to Unity’s GUI system.  We’ll use the system to build a twitter search client for android.  For the last session, we’ll move on to 3D game development and build an experience for the GearVR.

Intro to Unity – Part III – 3D & VR Games

The final session in this series is all about 3D game development and Virtual Reality.  Here, we’ll cover the differences between 2D & 3D games.  We’ll import some assets, setup animations, launch baseballs, then turn it into a VR experience.  After the session, you’ll be able to try out the virtual world we’ve built on the GearVR.

baseball1

Demo

Intro to Unity – Part II – Application Development (Twitter app)

This session will build upon what you learn in part I, but instead of building a game, we’ll make a twitter search client.  The focus here will be building UI systems using Unity’s UGUI system.  We’ll cover things like panels, scrolling, and images.  We’ll finish the session off with some mixing of 2D & 3D in the same app.

twitter1

Intro to Unity – Part I – 2D Games

In this session we’ll build a clone of a popular 2D mobile game in under an hour.  You’ll be introduced to the basics of the Unity3D engine and editor.  We’ll cover 2d physics & collisions, sprites, input, movement, and more.  By the end of the session we’ll build the working game to an android device.  After the session you should be able to recreate the basics of a few popular games.

Fish

Continue reading >
Share
1 4 5 6
Page 6 of 6