ME FIRST GAMES
Menu
games for me and you
![]() Writing your first script is like entering an unknown world. Whether you have programming experience or not, here are some general tips that can help you. 📌 When writing a MonoBehavior, the name of your class must match the filename exactly. If your script file is not named "PlayerController", then Unity will be unable to find the script. This becomes apparent when you can't add the script. 📌 GetComponent results need to be cached. GetComponent is not a performant call and thus you do not want to be calling it multiple times every frame. The better strategy is to cache your component in Awake or Start and then use the cached reference in the rest of the code. 📌 Attribute SerializedField allows you to reveal private variables in the Unity Editor. There is no need to make all your variables public. C# coding styles and good programming standards still apply. 📌 Serializing variables should only be done for objects that need to be linked through the Unity Editor. Whether it's playing an animation on an Animator or applying a force to a Rigidbody, this is how you will reference and control GameObjects in code. 📌 When things don't work, the first place to look is the Console in the Unity Editor. Forgot to link your serialized _rigidBody variable in the Editor, then Unity will throw an exception when that variable is dereferenced. 📌 Understand the dangers of static variables. MonoBehaviors are created and destroyed with the GameObject they are associated with. Any static variables you set may persist even after that object is destroyed. Be sure to clean up static variables. 📌 Make a Prefab: Scripts, like Prefabs, may be reused and added to many GameObjects. Most likely you'll be building a hierarchy of GameObjects with your script on the root GameObject. Try making a prefab and dropping multiple in your scene.
0 Comments
Leave a Reply. |
Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
Red MatterStar Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.
Archives
April 2021
Categories |
Copyright (c) 2020 Me First LLC
|