Nov 112011
 

To get your level working properly, you’ll want to establish borders and obstacles.  I’ll go over a few basics, but this is really a section that you can use to make the game your own unique product.  Before anything, there’s a quick addition we can make that will allow our game to expand as much as we would like.  Create a new javascript file and add the following:

var theBall : Transform;
function Update () {
transform.position.x = theBall.transform.position.x;
transform.position.y = theBall.transform.position.y;
}

Save it however you like and then drop it onto the main camera.  Now, wherever the ball goes, the camera will follow along.  What this will allow is a whole new capacity for level expansion.  Instead of a board that is only the size of your device’s screen, we can make it as complex as we want.  Have fun with it, but my only warning is that if you stretch the level, you’ll stretch the victory zone along with it.  Though theres no limit to how many different ways you can expand on what we have, just make sure you aren’t ruining the work you’ve already done.  Also remember that our world has gravity, which can allow for fun things such as stairs, tubes, or other complex additions… eventually.

I’m a firm believer in starting with something simple before going into a massive undertaking.  Allow yourself to complete something easier before you decide to expand.  As the example here, I’m not going to go too crazy.  We’re going to start with some basic walls, and I’ll leave them untextured so they can be easily seen in the images.

Start by creating some cubes.  Remember, cubes have colliders and everything needed by default.  Scale them to fit along the walls of your level, and be sure they are tall enough to really prevent the ball from escaping.  (Since the camera is overhead, taller is likely better.)

Make good use out of the right-click -> duplicate feature within the hierarchy, and save yourself time.  Before long, you can take a simple plane and make it into something much more interesting.

Yes, my level is boring.  Yours doesn’t have to be.   In fact, you can get creative and use some basic scripts to literally put some of the pieces in motion.  I won’t go into these more advanced features here because my aim is to deliver the basics and allow you to really let the project take off on your own steam.

For convenience, here are all the files needed to get everything going:  The fully-built APK for Android, the UnityPackage that contains the scene, prefabs, scripts and materials, or just the scripts themselves: CubeMover.js and CameraFollow.js.  Hopefully it makes things much easier to get started or aids in giving you a point of reference.

 Leave a Reply

Connect with Facebook