Summary - MonoBehaviour
- Game Development course
- Beginner
- Lesson 36/83
- 4 min
Reinforce the MonoBehaviour lifecycle with a summary task.
MonoBehaviour summary
In a class derived from MonoBehaviour, Unity calls three methods in order: Awake first, then Start, and then Update in every frame. Awake and Start run only once.
public class Oyuncu : MonoBehaviour
{
void Awake() { /* first */ }
void Start() { /* once */ }
void Update() { /* every frame */ }
}You can make your fields visible in the Inspector with public or [SerializeField].
Practice Lifecycle summary
In a class named Ozet, make a private int can field visible in the Inspector with [SerializeField]. In Awake, print "Oyun hazirlaniyor" and in Start, print "Can: 100" with Debug.Log, and in Update, increase the sayac variable by one every frame.
Starter code
using UnityEngine;
public class Ozet : MonoBehaviour
{
// 1) can adli private alani Inspector'da gorunur yap
// 2) Awake icinde "Oyun hazirlaniyor", Start icinde "Can: 100" yazdir
// 3) Update icinde sayaci her karede bir artsin
}Sample solution
using UnityEngine;
public class Ozet : MonoBehaviour
{
[SerializeField] private int can = 100;
int sayac;
void Awake()
{
Debug.Log("Oyun hazirlaniyor");
}
void Start()
{
Debug.Log("Can: 100");
}
void Update()
{
sayac++;
}
}Expected output
Oyun hazirlaniyor Can: 100
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the correct lifecycle order for a MonoBehaviour?
- Awake → Update → Start
- Awake → Start → Update Correct answer
- Start → Awake → Update
- Update → Start → Awake
Explanation: Unity calls Awake first, then Start; Update runs in the first frame and in every frame after that.
2 Write the method that runs every frame
void ____()
{
sayac++;
}
void Update()
{
sayac++;
}
Explanation: Update is called every frame; Awake and Start run only once.
3 MonoBehaviour summary table
| Term | Meaning |
|---|---|
Awake |
Startup method that runs first |
Start |
Preparation method after Awake |
Update |
Method that repeats each frame |
Inspector alanları |
Shown via public and [SerializeField] |