Camera.main is a search, not a variable

It looks free. It is not.

Camera.main is a search, not a variable

The problem

This searches the scene every frame.

void Update(){    transform.LookAt(Camera.main.transform);}

Camera.main finds the first enabled camera tagged MainCamera. That is a scene lookup, every frame, per script.

What it costs

Multiply it by scripts and by frames.

Scripts calling itPer framePer second at 60 FPS
11 lookup60
2020 lookups1,200
200 enemies200 lookups12,000

None of them return a different answer than the first one did.

The fix

Ask once. Keep it.

Camera cam; void Awake(){    cam = Camera.main;} void Update(){    transform.LookAt(cam.transform);}

Awake runs once. After that you are reading a field, which costs nothing.

The catch

Cache it, and know when it dies.

If you load a new scene, the old camera is destroyed and your field points at nothing.

Scene loads
the old camera is destroyed
Your cached field
now points at nothing
So
grab it again, or let a manager own it

Re-grab it after a scene load, or get the camera from a manager that owns it.

The rule

If it searches, keep it out of Update.

Camera.main
cache in Awake
GetComponent
cache in Awake
Find anything
cache, or avoid

Newer Unity caches Camera.main. The habit covers the rest.