Unity Tip: Magic Numbers! #shorts #unity #gamedev

preview_player
Показать описание
✅ Avoid Magic Numbers! Define simple variables with descriptive names.
👍 Learn to make awesome games step-by-step from start to finish.

💬 Magic Numbers are numbers in your code that are not immediately clear what they do.
They reduce code readability so avoid them at all costs.
Instead make them into proper variables with good names that clearly explain what the number refers to.

If you have any questions post them in the comments and I'll do my best to answer them.

See you next time!

#unitytutorial #unity3d #unity2d #unity​ #gamedev​ #indiegame​ #gamedevelopment #madewithunity​ #indiedev​

--------------------------------------------------------------------

Hello and Welcome!
I'm your Code Monkey and here you will learn everything about Game Development in Unity using C#.

I've been developing games for several years with 8 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.

I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.

--------------------------------------------------------------------
- Other great Unity channels:
--------------------------------------------------------------------

Рекомендации по теме
Комментарии
Автор

💬 Magic Numbers! It's a fun term for an important issue with an easy fix!

CodeMonkeyUnity
Автор

I remember when magic numbers was called hard coding.

dustypants
Автор

A bit more info about this:
if you think that is not optimized, it is! The compiler will optimize automatically your code (if you don't compile in O0, aka zero optimization).
That can have a drawback if you're using code coverage.

anonyme
Автор

With compiler optimisations these days I can't even think of when you'll ever need to use magic numbers. Great tip!

heatblayze
Автор

I love short videos, quite informative and easy to consume when you have chaotic weeks. Waiting for more.

Howdyhowthis
Автор

Great tip, if i am not wrong this tip was shared by you in some other video:d

sundarakrishnann
Автор

Simple, but powerful tip, a lot of people forget about that

BBdaCosta
Автор

I find myself defining consts at the least instead of magic numbers. But, some acceptable magic numbers that are hard coded would be 1 or -1, but depends on situation.

Cameo
Автор

(By the way, setting numbers as class variables allows you to tweak them with Inspector in Unity)

SMT-ksyp
Автор

Good clean quick tip. I feel a lot of indie devs skip the basic fundamentals of programming and need to brush up on the basics before tackling their grand scoped games.

rhenevers
Автор

Will you be making any updated Tutorial videos for Unity 2D platform creating showing a simple and easy method of adding in a crouch function (press down to crouch) with your gamepad or keyboard? A few people suggested i watch your channel from the Unity Forum but i see you dont have anything like that specific here. Pardon me if the question is too bothersome. I just find pulling that one thing off for my project difficult. Adding in walking. Jumping, attack and even camera follow seemed easiest to me than getting getting crouch to work properly

xDTHECHEMISTx
Автор

variable assignment make lags. It's memory allocation and serialisation.
Why do not use comments?
It's like not using pools or making new objects at any moment.

Evenmore, here context is clear not like
30 > DATA (20, 128, 96, 55, 0, 7, 120, 15)

genybr
Автор

And overall flows nicely into a video about self documenting code over commented code, so when is that one coming? ;-)

slothlair
Автор

please a tutorial about procedural animation or a better alternative if there is any, I've found some videos but I'm not advance so is quite difficult to understand them

dmqinbl
Автор

public const float AttackRange = 5;

Stop magic

nonamenoname
Автор

Thanks for video. I waiting for new ECS project video. From beginning to final stage. And more acrhitecrure tips not programming please. Everybody knows how to programm, but few pro in architecture and patterns.

GrinyaPLAY
Автор

Awesome! Sir do you have any tools that improves the performance of the code. For example changing other.tag to Compare.Tag or using 'string.Append()' instead of 'string +=' . I need a tool like this to improve my code performance

erdemakar
Автор

Well written code :)

Although next part might not be useful for Unity today...
There's a good example when magic number was super useful.
Check video by Nemean about faster inverse square root, which was used in Quake III and with their magic number.
Comment section there is gold as there's response from someone who saw it first hand back then.

JMIK
Автор

could you do a tutorial on how to plan a schedule on different things and then execute it?

bassenorberg
Автор

did you get your name from that one song by Johnathan Coulton?

madmonty
welcome to shbcf.ru