[Question] Necessary to create a script for stone?

Ben mentioned it’s less resources to check for the script instead of a tag, but is it better than just checking for the name of the game object? Also, why is it more efficient than checking the tag? He said “it can be checked at compile time,” but what does that mean?

I have the code below that checks for the object name, without checking for a script.
if (obj.name == "Gravestone") {Jump();}
Any reason not to use this approach?

Thanks.

Hi.
I think the reasoning here is, that you can give different jumpable objects this scripts.
Edit:Another benefit of doing it whith these scripts is that you can give an object multiple “tags”.

Computations can be performed at compile time and run time.

After you changed script in your editor, and you press a play button in Unity editor, compiler will process your script code and transform it into executable code. All this time after you pressed the ‘Play’ button until the game running is a compile time.

Run time is all the time while your game is actually running.
When there are lots of computations in run time, your game can slow down, so in general you would prefer to calculate as much as possible at compile time.

Now regarding an example shown in the video, I am not sure if that will actually work at compile time, because that method is called only when collision happens, so I think it was meant in general, that when possible, that call to GetObject can be resolved at compile time.
If someone can correct me if I am wrong

1 Like

Privacy & Terms