+ 5
Unity Game Development scripting tips
What tips do you have Unity scripting please put in language used
6 Answers
+ 4
a nice tip i used was to properly use the private and public keywords, so you dont have lots of GameObjects in your editor, and also, know your GameObjects!
+ 3
put in the code language
+ 3
thanks
+ 2
c#
+ 2
(some tips can be applied anywhere)
* As Bedida mentions, keep everything private unless you must not.
If you want to open a variable to the inspector instead of making it public you can use:
[SerializeField]
note*
In c# members are private by default (So you don't need to write private).
* Always use meaningful variable names.
* Follow some capitalization standards
For example,
int score;
float xPos, yPos;
const float MAX_SIZE = 15.3;
* Make proper usage of methods
-> If a task does something else specifically, turn it into a method and call the method instead of clogging all code in one method.
* Do not put to much code in the Update method unless you have to.
This runs every frame so can slow down your program if placed on many objects.
* Take into account 'design by contract'
-> assure errors are handled.
Check out:
https://docs.unity3d.com/ScriptReference/Assertions.Assert.html
* Avoid using:
GameObject.find ("objName");
It's slow. Only use it if you must.
Cache the result if used many times.
+ 1
Object pooling is a very useful concept for making games in Unity, a quick search on YouTube has some good tutorials. I code c# in unity