There’s a great article by Yegor Bugayenko called Need Robust Software? Make It Fragile. It’s about Fail Fast philosophy where you should write your code in the way that your application will fail as fast as possible if something is significantly wrong with your data or environment. When you’re building a mobile game with Unity then most probably you’re […]
Tag: Scripting
How to customize Unity script templates
When you’re creating a new script, Unity editor generates its contents and for C# script it uses the file name as the class name. It looks like this. using UnityEngine; using System.Collections; public class MyCustomScript : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update […]
Rendering custom GUI on Scene view
If you’re using assets from the Asset Store then most probably you realized that some scripts introduce custom GUI elements inside the scene view. Custom GUI elements may be very helpful in many cases and they are also easy to implement! Today I’d like to show how to do this. First, you need to know when custom […]
Executing Custom Scripts from Unity’s Menu
You can do wonderful things with your Unity editor via scripting. For instance, you can write a script to populate your scene with random objects. All you need is a method of executing those scripts. Let’s talk about how to put your scripts into any menu. For this purpose, we will use MenuItem annotation and write […]
UnityToolbag – Library Overview
One of the greatest powers of the Unity is extensibility. You can see this especially by looking at the Asset Store. There’s plenty of scripts that will extend your Unity editor capabilities and some of them are totally free! In Overview series we will talk about this kind of assets. UnityToolbag is a carefully prepared set […]
Profiling Unity Application with Profiler Samples
The Unity Profiler Samples is something that most of Unity users are unaware of. Yet it can be extremely helpful if you want to find out what amount of resources your code takes during the execution. If you’re already familiar with built-in profiler then you might know that by default it is not profiling all method calls. Also, […]
Use Invoke methods to execute code at a given time
What if you need to invoke a specific code in 2 seconds? You can write an accumulator that counts time, use coroutine to wait for 2 seconds or simply use Invoke or InvokeRepeating methods. Invoke Invoke is a public method of MonoBehaviour class (so you can access it from your game scripts). It takes method name and time as […]
Custom gizmos with OnDrawGizmos
Did you know that by implementing OnDrawGizmos() method in your scripts you can draw a custom gizmo? Last time we talked about how to use icons’ settings to assign various icons to invisible game objects. Yet if you have some experience with scripting then you can create your own gizmos. Basic Example Gizmo drawing can be done using […]
Use decorator drawers to improve inspector view of your scripts
If you’re writing a custom script then most probably you want to manipulate its public field values from the Inspector. By default, the Inspector fields are placed next to each other and the field name is the only information that you receive. You can write a custom editor, but this requires creating another script with a […]
ExecuteInEditMode will run your script in edit mode
You might be familiar with the workflow that all of your game scripts are working only when you hit the Play button. Did you know that you can force some scripts to be running even when you’re in the edit mode? Why would you do that? I mean that you may have player scripts, enemies scripts, weapons […]