# 🎮 Unity C# Basics: Start() vs Update()

## 🚪 **My First “Wait, Why Didn’t That Run?” Moment**

My first Unity script? I was hyped. Like, *finally* coding a game.  
Dropped some code in `Start()`. Hit Play.

…nothing.

The cube showed up, the scene was fine, but my code? Dead silent. Not even a log.

So I was like, “ok maybe I did it wrong.” Threw the same code into `Update()`.  
Hit Play. Boom, it worked. 🎉  
But also… it *wouldn’t stop*. Just kept spamming like it was on loop.

And that’s when it clicked: `Start()` and `Update()` aren’t the same at all. They look similar, but they live totally different lives.

### `Start()` — runs once

Think of `Start()` as the wake-up call. Fires a single time when the GameObject comes alive. That’s it.

```
void Start()
{
    Debug.Log("I run once at the beginning 🚀");
}
```

Stuff it’s actually good for:

* Setting player health.
    
* Spawning enemies when the level begins.
    
* Playing an intro sound.
    

It’s like the setup crew — they do their job and leave.

### `Update()` — runs forever

`Update()` is Unity’s heartbeat. It ticks every single frame while the object’s active.

```csharp
void Update()
{
    Debug.Log("I run every frame 🔄");
}
```

What it’s good for:

* Moving characters.
    
* Checking inputs.
    
* Updating scores, timers, UI.
    

If it needs to keep running, this is where it goes.

### My “aha” cube

Here’s the script that made me get it:

```csharp
using UnityEngine;

public class StartVsUpdate : MonoBehaviour
{
    void Start()
    {
        transform.position = new Vector3(Random.Range(-5, 5), 0, 0);
        Debug.Log("Cube spawned at a random spot 🎲");
    }

    void Update()
    {
        transform.Translate(Vector3.right * Time.deltaTime);
    }
}
```

What happens:

* Game starts → cube spawns somewhere random. (`Start()` did that.)
    
* While it runs → cube drifts right forever. (`Update()` doing laps.)
    

That’s when it finally clicked for me.

### My tiny cheat sheet

* `Start()` = one-time setup.
    
* `Update()` = constant loop.
    

Or if you like it simple:

* Start = first impression.
    
* Update = daily grind.
    

### Wrap up

The trick isn’t picking one over the other. It’s knowing when to use which.  
`Start()` sets the stage.  
`Update()` keeps the play going.

And yeah, the first time I saw my cube spawn randomly and slide away… I just sat there grinning like:

“Alright. I can actually make a game.” 😅
