Tag Archives: unity

Using Microsoft Visual Studio Code as the external code editor in Unity

Yesterday during the Build 2015 developer conference, Microsoft announced and released their new editor called Visual Studio Code (or just “Code” for short).  Code is free, runs on Windows, Linux and Mac OSX.  I immediately wondered if it would be a good alternative to MonoDevelop as a code editor for use in Unity.  After a bit of fiddling, I managed to get it all working quite nicely, with proper code completion etc.  There are some caveats though, it does not work perfectly, but the caveats are easily worked around.

Here are the steps I followed on my Mac:

Continue reading

Adventures in Unity: Making an object move one step at a time – Tetris-style

I hit a small mental block with Project X (codename for my RealGame™ that I am trying to build in Unity), so decided to try to do something a bit simpler first, and see how that goes, purely as a learning experience, getting used to Unity and its quirks.  I decided to make a Tetris clone.

At first I thought “Hey, Unity has a physics engine, Tetris blocks drop down, I can use the physics engine!” – but alas, no, that’s not the greatest idea, as you essentially need to switch off everything about the physics engine, except for gravity really, to make it work.   Too much work, and too much randomness that could creep in.   Especially if you’re using the 3D engine but presenting it in 2D, as I had intended initially.  I figured the final game could present the blocks in 3D as they drop down, maybe move the camera around a bit depending on which side of game grid the object is, etc.  So I am sticking to 3D for now.

Ah, but the reason you’re here, you want to make an object move on “step” at a time, like a tetris block moves, over time.  I just created a script for that, see it at my GitHub repo: StepObject.cs

Here’s how it works:

Here is just the beginning of the script, we make our four public variables available and initialise a couple of private variables.  Our Start() method merely checks that we have the required variables to be able start moving at startup, if so required, so if we have SecondsPerStep and a MoveDirection is set, we make the Moving private variable equal to whatever you chose in the Inspector for the StartMoving tickbox.

Here is the meat of the script, quite small actually, not very meaty at all.  In every Update, we increase the value of the Timer variable by Time.deltaTime.  We use the Timer variable to count how much time has passed since the last time the object moved.

Et voila.  Done.  Very simple actually.  To use this in a Tetris-like game, you would adjust the SecondsPerStep variable over time as the difficulty increases, lowering that value for each level gained.  You would probably start with a number of 2 seconds per step at level one.  If you create your game grid to be one unit per square, then your MoveDirection Vector would be equal to (0,-1,0).

Please give me feedback if you use this script, and let me know how things go.

Here’s the full script code:

 

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.

background_stars_rotating