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 12 of 17
5 minBeginnerFree
XP0/17 · 0%
Next lesson
Course contents
  1. 🧪 Variables and Data Types – Your Game’s Memory Bank5 min
  2. 🛠️ Methods and Parameters – Giving Your Game Instructions5 min
  3. 🧠 If This, Then That – Writing Decisions in Code5 min
  4. 🔁 Loops – When You Want Something to Happen Again… and Again5 min
  5. 🧱 Classes and Objects – Building Blocks of Game Logic5 min
  6. ⚙️ How Unity "Talks" to Your Code5 min
    1. 👑 What is MonoBehaviour?
    2. 🚀 Start() – Runs Once
    3. 🔁 Update() – Runs Every Frame
    4. 🧪 Example Script
    5. 🛠️ Other Useful MonoBehaviour Methods
    6. 🧠 Recap
    7. 🧪 Mini Challenge: Frame Counter
    8. 🚀 What’s Next?

Learn Unity and C# by Making Games / C# Fundamentals

⚙️ How Unity "Talks" to Your Code

Learn MonoBehaviour, Start, Update, and the Unity lifecycle basics.

Project setup checklist

Before you start

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

You’ll be able to

  • Explain MonoBehaviour
  • Use Start and Update
  • Recognize common Unity event methods
  • You’ve learned how to write scripts.
  • Now let’s learn how Unity knows when and how to run your code.

In Unity, there are special built-in methods - like Start(), Update(), and OnCollisionEnter() - that Unity calls automatically at specific times.

This is made possible through MonoBehaviour, Unity’s magical base class that connects your scripts to the engine.


👑 What is MonoBehaviour?

All your Unity scripts inherit from this class:

Example
csharp
1public class MyScript : MonoBehaviour2{3    // Magic lives here4}

By inheriting from MonoBehaviour, Unity can call special methods like Start() and Update() without you needing to do anything else.

Info

🧙 Think of MonoBehaviour as the wizard behind the curtain that hooks your code into the game loop.

🚀 Start() – Runs Once

Example
csharp
1void Start()2{3    Debug.Log("The game has started!");4}
  • Called once at the very beginning (when the object becomes active)
  • Great for initialization, setting values, or printing welcome messages
  • Happens before the first Update()

🔁 Update() – Runs Every Frame

Example
csharp
1void Update()2{3    Debug.Log("Still running...");4}
  • Called every frame - 60+ times per second depending on your hardware
  • Ideal for real-time logic like: Player input
  • Moving objects
  • Checking timers

Tip

💡 Too much heavy stuff in Update() = lag town. Use wisely.

🧪 Example Script

Example
csharp
1using UnityEngine;2 3public class HelloUnity : MonoBehaviour4{5    void Start()6    {7        Debug.Log("Game started");8    }9 10    void Update()11    {12        Debug.Log("Frame running...");13    }14}
  • Attach this script to a GameObject, hit play, and check the Console:
  • You’ll see “Game started” once, and “Frame running…” repeatedly.

🛠️ Other Useful MonoBehaviour Methods

MethodWhen it Runs
Awake()Before Start() (used for internal setup)
FixedUpdate()Called at fixed intervals (physics-related)
OnCollisionEnter()When object collides with another
OnTriggerEnter()When trigger collider is entered
OnDestroy()When the object is removed from the scene

We’ll explore these more in future lessons. For now, Start() and Update() are your go-to tools.


🧠 Recap

  • MonoBehaviour connects your code to Unity’s event system
  • Start() runs once when the object activates
  • Update() runs every frame (use it for live logic)
  • These methods let your scripts become interactive parts of the game world

🧪 Mini Challenge: Frame Counter

  1. Create a new script called FrameTracker.cs
  2. In Update(), increase a counter every frame
  3. Every 60 frames, print "One second-ish passed"
  4. Reset the counter after logging

Bonus: Try printing a message every 5 seconds using a float timer instead!


🚀 What’s Next?

  • Congrats, you’ve finished Section 2! 🎉
  • You now know the basics of variables, methods, logic, loops, and Unity’s script lifecycle.

Next up, we’ll build our very first game together - a classic clicker game to put your skills into action!

👆 Go to Section 3 → Your First Game – Clicker Game

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

  • MonoBehaviour connects your script to Unity.
  • Start runs once when an object becomes active.
  • Update runs every frame, so keep it intentional.

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

🧱 Classes and Objects – Building Blocks of Game Logic

5 min

Next Lesson

🧱 Building the Foundation for Your First Game UI

5 min

Back to course