DMG Forge
ArticlesUnity TipsGamesAssets WIPCoursesAbout
ArticlesUnity TipsGamesAssets WIPCoursesAboutFree resources
LV 10 XP
Free resources
Now building:Me and M.A.X

DMG Forge

Unity tips, articles, assets, and devlogs for creators who want to build and finish.

AchievementsSavedSkill tree
Learn Unity and C# by Making GamesLesson 14 of 17
5 minBeginnerFree
XP0/17 · 0%
Next lesson
Course contents
  1. 🧱 Building the Foundation for Your First Game UI5 min
  2. ✍️ Let’s Make That Button DO Something5 min
    1. 🧰 Step 1: Create the Script
    2. 💻 Step 2: Write the Click Logic
    3. 🧪 Step 3: Hook Up the Button
    4. 🔗 Step 4: Link the Text Label
    5. 🧪 Test It!
    6. 🧠 Recap
    7. 🧪 Mini Challenge: Customize It!
    8. 🚀 What’s Next?
  3. ✍️ Make Your UI Feel Alive!5 min
  4. 🔊 Make Every Click Sound Delicious5 min
  5. 🖱️ Project 1: Clicker Game – Your First Fully Playable Game5 min

Learn Unity and C# by Making Games / Clicker Game Project

✍️ Let’s Make That Button DO Something

Connect a button to code and make the game count player clicks.

Project setup checklist

Before you start

  • Basic computer skills
  • A willingness to build along inside Unity

You’ll be able to

  • Create a click counter script
  • Connect a UI button
  • Update state when clicked
  • Time to turn our boring button into something interactive!
  • In this lesson, you’ll write your first real game logic in Unity:
  • When a player clicks a button → increase a counter → update the UI text.

Let’s click like it’s 1999.


🧰 Step 1: Create the Script

  1. Right-click in the Project window → Create → C# Script
  2. Name it ClickCounter
  3. Drag it onto any GameObject in your scene (like an empty object called GameManager)

💻 Step 2: Write the Click Logic

Open ClickCounter.cs and replace the code with:

Example
csharp
1using TMPro;2using UnityEngine;3 4public class ClickCounter : MonoBehaviour5{6    public int clickCount = 0;7    public TextMeshProUGUI clickText;8 9    public void CountClick()10    {11        clickCount++;12        clickText.text = "Clicks: " + clickCount;13    }14}

Let’s break it down:

  • clickCount keeps track of how many times you’ve clicked
  • clickText is the UI label we update
  • CountClick() is the method that runs when the button is pressed

🧪 Step 3: Hook Up the Button

  1. Select the Click Button in the Hierarchy
  2. In the Inspector, scroll to the Button (Script) component
  3. Under On Click(), click the + icon
  4. Drag the GameObject with your ClickCounter script into the slot
  5. From the dropdown, choose → ClickCounter → CountClick()

Now the button knows what function to run when clicked!


🔗 Step 4: Link the Text Label

Select the GameObject with your ClickCounter script and in the Inspector:

  • Drag your ClickCountText UI element into the Click Text field

This connects the script to the visual label. 🧠


🧪 Test It!

  1. Hit Play
  2. Click the button
  3. Watch the counter go up!

Congrats - you just made a working clicker mechanic! 🎉


🧠 Recap

  • Created a script with a public method
  • Connected that method to a UI button
  • Updated a text label from code
  • Built your first working game mechanic 🔥

🧪 Mini Challenge: Customize It!

  • Add sound or animation when the button is clicked
  • Let the player earn 2 points per click (instead of 1)
  • Change the text color once they reach 10 clicks
  • Add a "Reset" button that sets the count to 0

🚀 What’s Next?

  • Let’s take that UI to the next level and make it dynamic and polished.
  • We’ll work on visual updates, better font effects, and auto-scaling.

🖼️ Go to Lesson 15 → Updating Text Dynamically in Unity

Try It Yourself

  • Open Unity and recreate the smallest version of this lesson's main idea.
  • Change one value, name, or setting so you can see the cause and effect.
  • Use the Console or the Game view to confirm the result before moving on.

Keep it small enough to finish in five minutes, then write down what changed and what Unity showed you.

  • Reading the whole lesson before trying the first concrete step.
  • Changing multiple settings at once and losing track of what mattered.
  • Ignoring Console errors because the scene still appears to load.

Quick Check

What is the best next step after reading a lesson section?

Key Takeaways

  • UI events can call your methods.
  • A counter is just state plus an action.
  • Small feedback loops make code feel real.

Resources

download

Project setup checklist

Use this before starting a new Unity prototype.

reference

Unity Manual

Official reference for Unity editor concepts, components, and workflows.

reference

Unity Scripting API

The fastest way to verify classes, methods, and Unity-specific behavior.

download

DMG Forge Resources

Checklists and creator resources for keeping projects moving.

Previous Lesson

🧱 Building the Foundation for Your First Game UI

5 min

Next Lesson

✍️ Make Your UI Feel Alive!

5 min

Back to course