Create a game like Spring Ninja with Unity – step 1

I received a lot of good feedback both with my Spring Ninja Phaser prototype post and with Flappy Bird Unity prototype, so I decided to merge the best of both concepts and create a Spring Ninja prototype made with Unity.

This will also allow readers to understand the code behind the creation of the Phaser prototype.

The tutorial will be split in two parts, because these are the first Unity tutorials on this blog and probably some readers are still not that used to Unity mechanics.

Let’s jump straight to the point, and let’s see the assets used in the prototype:

What we have in Hierarchy window is the Main Camera and a Game Engine empty object, where we are going to embed the main script. The game is also set to run at 640×480. If you have troubles to set up the camera, create game objects, change resolution or create and expand game prefabs, like the one we are going to see in a moment, there’s a detailed tutorial here.

Now, let’s have a look at Assets window:

* mainScene: the main scene, save it before you close the project

* MainScript: the main script, which will be added to Game Engine

* ninja: the ninja PNG image

* ninjaPrefab: the prefab of the ninja, containing the ninja image, NinjaScript script, Rigidbody 2D component and Box Collider 2D component both with default attributes

* NinjaScript: the script to be attached to ninjaPrefab

* pole: the pole PNG image

* polePrefab: the prefab of the pole, containing the pole image, PoleScript script, Rigidbody 2D component with Is Kinematic checked and Box Collider 2D component with default attributes.

* PoleScript: the script to be attached to polePrefab

* powerbar: the power bar PNG image

* powerbarPrefab: the prefab of the power bar, containing the power bar image and PowerScript script. No physics for this prefab.

* PowerScript: the script to be attached to powerbarPrefab

With this in mind, have a look at what we are going to build:

Press and hold the mouse to charge, select to jump. Unfortunately, you will fall to death, but more poles where to land on will come in next step.

Now, it’s time to have a look at the scripts, starting from MainScript. I am also using Unity’s Tags and Messages. You can find information about these concepts in the post Unity2D Circle Chain prototype step 2: adding explosions.

As you can see, the main script does most of the dirty job, leaving other scripts just minor things. Let’s see PoleScript:

Then PowerScript:

and finally NinjaScript:

During next step we’ll complete the prototype, meanwhile download the project.

  • Ivan

    Hi Emanuele,

    Its great article. Thank you a lot.

    Could you take a look to Update method at main script?
    You use findObject method for the same object several times. I think it could “expancive” call.

    May be we may provide this Object as public property and put to script from Unity.
    Or store link to this object when we have found it first time.

    For me its a big pain to do unity game work fast.
    (sry my English. I hope it was clear to understand)

  • Pingback: Create a game like Spring Ninja with Unity – step 2 | Emanuele Feronato()

  • Pablo

    Hey, Emanuele!
    Will you add some tutorials about Match3 in Unity?
    It will be great!

  • Dragonex

    Hello, i would love to see a pong tutorial or arkanoid tutorial for Unity! made by you.

    I like the way you explain.

  • Pingback: Lesson 2: Spring Ninja Clone | CTE Courses()