This blog post is intended for Unity users who are still new to scripting but have a few basics worked out.
I'm going to assume you know the following:
- Basic C# knowledge
- Basic knowledge of scripting in Unity
- Understand how to navigate around the Unity editor
Are you often writing code like this?
public class Thing : Monobehaviour
{
public OtherThing otherThing;
private void Update()
{
otherThing.Do();
}
}
Then you go to the Unity inspector and add the drag and drop the GameObject that contains OtherThing onto Thing? This is an incredibly easy way to get references to objects but causes quite a few issues.
Having to drag and drop all of your references quickly gets out of control and becomes quite tedious. Imagine having to drag and drop multiple references on even 10 or so GameObjects within your scene. This is also not including the fact that it may be confusing for someone else to wire up your scripts.
So how can we go about eliminating some of these drag and drop references. Well, you might do a quick Google search and see people talking about different design patterns to help with this problem. However, I assume that you do not know anything about design patterns much less know which ones to use. Is there a simple to understand Unity way of doing this? The answer is yes and there are actually a few ways to go about it.
I want to keep these blog posts relatively short so that it's easier to absorb the information. Tomorrow, we will go about different Unity ways of solving our issues. I'll see you then.