Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
This post is about how to help yourself organise scripts in the Unity Editor using Tool Tips and Headings.
This post is about how to help yourself organise scripts in the Unity Editor using Tool Tips and Headings. When you are developing as an Indie there can be long gaps between coding runs. There is never enough time and so much to do so using anything that can help you quickly understand what those behaviours are supposed to be doing is a godsend (and adds to your godspeed).
Take this script for example from our game currently in development Endless Elevator.
This is the raw Editor display before beautifying:
I come back to this after a few days and have no idea what all those things should be and as they are so terribly unorganised it makes it all the harder to work it out. Sure the code is commented and hell I wrote the stuff but it still takes time.
This is the same script with the addition of Headers and Tooltips (unfortunately the Tooltips are a bit hard to capture in a screen shot but you all know what they are).
Much Easier!
I’ll use a quick example project to demonstrate how to use Tool Tips and Headings. They are super quick and easy. I’ll also go over another extremely useful Editor function which is the Range. The Range can be used to clamp down a variable between a maximum and a minimum. This allows greater control over it’s setting while working on your game in Run Time so that you can tweak the variables easier.
Have a look at this example script:
HandyEditorTips Class
using UnityEngine; public class HandyEditorTips : MonoBehaviour { [Header("Speed Settings")] [Tooltip("Speed value between 100 and 500.")] // Show this float in the Inspector as a slider between 100 and 500 [Range(100.0F, 500.0F)] public float speed = 100; [Header("Point to Rotate Around X Axis")] [Tooltip("Location Across the screen on the X axis")] public float vector_x = 0; // Update is called once per frame void Update () { // Rotate the object around the given point // (Point to rotate round, direction of rotation, speed * frame rate delta) transform.RotateAround(new Vector3(vector_x, 0, 0), Vector3.forward, speed * Time.deltaTime); } }
This script is added to the Sphere in the project and the Slider is a huge help in setting the required speed of turning.
Juxtapose this with the other setting for the X Axis vector variable and see when I try and use that when it’s not clamped into some sensible settings. It sends my Sphere cycling all other the shop.
Video Player
It’s not groundbreaking stuff I know. But it’s easy to implement and does make your coding job easier in the initial phases. Once you’ve got all your scene elements into some kind of decent shape you can start moving those variables that shouldn’t be exposed into a private scope and setting them to static.
Here is the Unity API Documentation Links if you want to do more reading:
https://docs.unity3d.com/ScriptReference/TooltipAttribute.html
https://docs.unity3d.com/ScriptReference/HeaderAttribute.html
https://docs.unity3d.com/ScriptReference/RangeAttribute.html
Read more about:
BlogsYou May Also Like