Projects Inventory

Creating Gameplay UI and Animations Project (Pin The Needle Game) in Android

Creating Gameplay UI and Animations

Submitted by: razormist
Operating System: Android

Step 1: Creating the Gameplay UI Canvas

Step 2: Adding the Background Image

Step 3: Adding the Quit Notification Prompt

Inside Notification:

Step 4: Creating Notification Animation

Step 5: Camera Animation (Optional)

Step 6: Triggering Animations via Script

Example Script to Show Notification:

csharp

Attach this to a GameObject and link the Notification animator in the inspector.

Final Output

 

Pin The Needle Tutorial — Simple Classic Game for Android/iOS

Submitted by: razormist
Operating System: Android

Overview

In this tutorial, we will create a simple arcade-style game called “Pin The Needle” using the Unity Game Engine and C# scripting. Unity is a powerful cross-platform development environment used for creating both 2D and 3D games. It supports drag-and-drop functionality, real-time previews, and scripting in both C# and JavaScript.

Minimum Requirement:
Unity Version 5.6.1f1 or higher.
(Recommended: Use a recent version of Unity as older ones may cause compatibility issues.)

Tutorial Outline

1. Getting Started – Creating the Project

2. Setting Up – Resolution, Platform & Asset Organization

3. Creating Gameplay UI and Animations

4. Creating Rotator and Pin Object

5. Creating Spawn Point and Scoring

6. Creating Gameplay Controller

7. Creating Success and Failed Scenes

8. Publishing the Game

Result

After following the steps, you’ll have a working version of Pin The Needle with:

PART 1: Creating the Rotator (Target Object)

Objective

Create a circular GameObject that continuously rotates. The pins will attach to this.

Step 1: Add the Target Sprite to the Scene

  1. Locate the sprite (a circular shape, usually) in your Project window under Assets > Sprites.

  2. Drag the sprite into the Scene View or the Hierarchy.

  3. Rename the GameObject to “Target” for clarity.

Step 2: Set Up Components

Add Circle Collider 2D

Step 3: Create a Script for Rotation

  1. In the Project window, go to Assets > Scripts.

  2. Create a subfolder named Gameplay.

  3. Right-click in the folder and create a C# script named Target.

  4. Double-click to open and paste the following code:

csharp

Explanation:

  1. Attach the script to the Target GameObject:

    • Drag the script to the Inspector of the Target.

    • In the Inspector, set Speed = 100.

Step 4: Sorting Layers

Sorting Layers define render order in 2D.

  1. Open Tags & Layers > Sorting Layers (from the top of the Inspector).

  2. Add the following layers in this order:

    • Target

    • Pin

    • CanvasLayer

    • Number

  3. Assign the Target GameObject to the “Target” sorting layer.

PART 2: Creating the Pin Object

Objective

Create the pin GameObject that is thrown toward the target and sticks to it upon contact.

Step 1: Duplicate the Target

  1. Right-click the Target GameObject and choose Duplicate.

  2. Rename the duplicated object to “Pin”.

  3. Remove the Target script from the Pin.

Step 2: Configure Pin Components

Add Rigidbody2D

Add AudioSource

Step 3: Add Child GameObject and UI

  1. Right-click on Pin in the Hierarchy → Create Empty → name it e.g. PinCount.

  2. Create a UI > Text inside the PinCount GameObject.

    • This will show the pin count or any related information.

    • Customize the Text, Font, Size, Color, etc., as per UI design.

Step 4: Create the Pin Script

  1. In Scripts > Gameplay, create a script called Pin.cs.

  2. Paste the following code:

csharp

Explanation:

Step 5: Apply Script & Settings

  1. Drag and attach the Pin script to the Pin GameObject.

  2. Set the Sorting Layer to “Pin”.

  3. Set Order in Layer = 1 (to appear in front of the Target).

  4. Adjust any script variables in the Inspector if needed.

Step 6: Create Pin Prefab

  1. Drag the Pin GameObject into your Prefabs folder in the Project window.
    This makes it reusable at runtime.

  2. Delete the Pin GameObject from the scene.
    You’ll spawn it via script when the player throws a pin.

 

PART 3: Creating the Spawn Point (Spawner)

Objective

To spawn a Pin prefab from a fixed position every time the player taps the screen.

Step 1: Create a Spawn Point GameObject

  1. In the Hierarchy, right-click and choose Create Empty.

  2. Rename the GameObject to Spawn Point.

  3. Position it slightly below the target (where the pin should originate from).

    • Example: Set its Transform.Position to something like (0, -4, 0) (adjust as needed).

Step 2: Create the Spawner Script

  1. Inside your Scripts > Gameplay folder, create a new C# script named Spawner.cs.

  2. Open the script and add the following:

csharp

Explanation:

Step 3: Attach and Configure

  1. Attach the Spawner script to the Spawn Point GameObject.

  2. In the Inspector:

    • Drag the Pin prefab into the Pin Prefab field.

    • Drag the Spawn Point itself into the Spawn Point field.

Now when the user taps or clicks, a pin will be instantiated at the correct position.


PART 4: Creating the Scoring System

Objective

To keep track of the number of successfully pinned objects and display the score on the screen.

Step 1: Add UI Text for Score

  1. Right-click in the HierarchyUI > Text (or UI > Text - TextMeshPro if you use TMP).

  2. Rename it to ScoreText.

  3. Customize it in the Inspector:

    • Font Size: e.g., 36

    • Alignment: Center

    • Position: Top-center of screen (e.g., (0, 200, 0) for anchored canvas)

    • Color: White or something visible

    • Initial Text: Score: 0

Step 2: Create a ScoreManager Script

  1. Inside Scripts > Gameplay, create a script named ScoreManager.cs.

  2. Add the following:

csharp

Explanation:

Step 3: Link UI to Script

  1. Create an empty GameObject in the Hierarchy, name it ScoreManager.

  2. Attach the ScoreManager script to it.

  3. Drag the ScoreText UI element into the scoreText field of the script.

Step 4: Update the Pin Script to Add Score

  1. Open the Pin.cs script and modify the OnTriggerEnter2D() method like this:

csharp

Now each time a Pin hits the Target, the score increases by 1.

Final Checklist

Feature Done?
Spawn Point created
Pin spawns on tap/click
Pin prefab configured
UI Text created for score
ScoreManager script functional
Score increases on successful pin

PART 6: Creating the Success Scene

Objective

To display a success message when the player completes a level and provide a button to go to the next level.

Step 1: Create the Success Scene

  1. Go to File > New Scene, then Save As → name it Success.

  2. In the Hierarchy, right-click → UI > Canvas.

  3. Also add UI > Event System if not automatically created.

Step 2: Add a UI Image for Background

  1. Inside the Canvas, right-click → UI > Image.

  2. Select the image in the Inspector.

    • Assign a suitable sprite from Sprites folder to the Source Image field.

    • Resize it to cover the full screen.

Step 3: Add Success Text and Button

  1. Inside the Canvas:

    • Add a Text object → set it to something like “Level Complete!”.

    • Add a Button below the text.

      • Change its label to “Next Level”.

      • Adjust color, font, size, alignment as needed.

Step 4: Create the NextLevelController Script

  1. Create a new Empty GameObject in the scene, name it Next Level Controller.

  2. In Scripts > GameControllers, create a script: NextLevelController.cs.

  3. Add this code:

csharp

Step 5: Hook Up the Button

  1. Select the Next Level Button in the Canvas.

  2. In the OnClick() section:

    • Drag the Next Level Controller GameObject into the slot.

    • Select the method: NextLevelController → LoadNextLevel().

PART 7: Creating the Failed Scene

Objective

To show a “Level Failed” screen with a button to retry the current level.

Step 1: Create the Failed Scene

  1. Duplicate or create a new scene, name it Failed.

  2. Copy these from your Success scene or Gameplay scene:

    • Canvas

    • EventSystem

  3. Paste them into the Failed Scene‘s Hierarchy.

Step 2: Update UI Text and Button

  1. Change the main Text to something like “Level Failed!”.

  2. Change the Button Label to “Try Again” or “Retry”.

Step 3: Create the RestartController Script

  1. Create a new Empty GameObject → rename it to Restart Controller.

  2. In Scripts > GameControllers, create a script: RestartController.cs.

  3. Add the following code:

csharp

Step 4: Hook Up the Retry Button

  1. Select the Retry Button in the Canvas.

  2. In the OnClick() section:

    • Drag the Restart Controller GameObject into the slot.

    • Select the method: RestartController → RestartLevel().

Final Integration Tips

Task Details
Add all scenes to Build Settings File > Build Settings > Add Open Scenes
Use SceneManager.LoadScene() To move between scenes
UI elements reuse Canvas, Buttons, Text for consistency
Button OnClick() binding Drag GameObject with script into slot and select method

 

Download Code Here: Pin the Needle Classic Game 

 

Exit mobile version