CodeBlanks Logo Icon CodeBlanks

The Update method

Learn how the Update method runs every frame.

What is Update?

The Update method is called once in every frame of the game. The repeating part of the game loop runs here. How often the code runs depends on the frame rate.

void Update()
{
    sayac++;
}

The code above increases the sayac variable by one every frame.

Update as a loop

Every line inside Update runs during the frame and starts over in the next frame. This is why one-time work goes to Start, not here. Continuously changing work belongs to Update.

void Update()
{
    sayac = sayac + 1;   // repeats every frame
}

In short, Update is the heart of the game loop.

Practice Counter loop

In a class named Sayac, declare an int tur field. In Start, set tur to 0 and print "Oyun basladi" with Debug.Log. In Update, increase tur by one every frame.

Starter code

Player.cs
using UnityEngine;

public class Sayac : MonoBehaviour
{
    int tur;

    // Start icinde tur sifirlansin ve "Oyun basladi" yazdirilsin
    // Update icinde tur her karede bir artsin
}

Sample solution

Player.cs
using UnityEngine;

public class Sayac : MonoBehaviour
{
    int tur;

    void Start()
    {
        tur = 0;
        Debug.Log("Oyun basladi");
    }

    void Update()
    {
        tur++;
    }
}

Expected output

Oyun basladi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How does sayac change when the code below runs?

Player.cs
void Update()
{
    sayac++;
}
  • It increases by one every frame Correct answer
  • It increases once per second
  • It increases only once
  • It never changes

Explanation: Update is called every frame, so sayac++ runs once per frame.

2 Increase by one every frame

Question
    void Update()
    {
        sayac ____;
    }
Answer
    void Update()
    {
        sayac ++;
    }

Explanation: sayac++ adds one, and because Update runs every frame the increment repeats.

3 Concepts of Update

Term Meaning
void Update() Called once every frame
Frame A single update step of the game
sayac++ Increases by one every frame
Kare hızı Frames per second

All lessons in Beginner