Adventures in Unity: Background tiling and rotating

So Ive been playing around with Unity3d the past couple of weeks, during my spare time (and sometimes in the middle of the night).  I have to say, it’s a lot of fun, and I’m excited to try to make my first game.

I have so many ideas for games I want to make, I have to focus on sticking with just one.

Having no real experience with C#, and C# being the first language that I saw being used in tutorial videos about Unity, I am actually finding it quite easy to transition from Java to C# for this development.  Lots to learn though. So I decided to share some of the scripts that I’m writing for my first game (sssshhhhhh, it’s still a secret, but needless to say it’s a clone of another game, with some added extras, or, at least, will be).  Finally a reason to use my Github account.

My first script is a simple little Background tiling script.  The premise is simple, create a plan, add the script, attach the script to the plane.  Click on the plan and configure the script’s public variables, at minimum you should attach a prefab (generally a flat sprite, some image maybe) as the “BackgroundImage” property.  There is also some optional values you can tweak to make the script work a bit better to your liking.  The script auto-calculates how many tiles of the provided prefab it should create to fill at least the viewport, so it works best in 2D mode, with the camera looking straight at the plane.

background_stars_inspectorA couple of the features of the script:

  • auto-calculates number of tiles required to fill viewport
  • Optional background rotation
  • Optional Z Offset for tiles
  • Optional number of extra tiles to add on both x and y axis
  • Optional flipping of every other tile (180 degree rotation on the z axis)
  • Adjustable rotation speed (Number of degrees to rotate per second)

Find the script in my AdventuresInUnity repository here on github: CreateBackground.cs

I’ve also been toying with uploading some tutorials on what I’ve learnt in Unity, from a beginner’s point of view, let me know if you’re interested. Anyway, enjoy the script, and please let me know if you use it, and/or if you have some edits for it.  Feel free to send some github pull requests.


Leave a Reply

Your email address will not be published. Required fields are marked *