Accessing GameObjects using drag-and-drop versus writing code

Unity has a rather neat feature that allows us to assign GameObjects to variables without writing the code. It definitely has its uses, however, if it's not really necessary, I recommend assigning GameObjects in code. Why?

Tip

Six months from now, when you are the stranger looking at your own code, you may look at it and wonder why your code looks incomplete. It's your game though, so you can create it anyway you please. I'm just saying, don't go hog wild with drag-and-drop and then later wonder what it was you were trying to accomplish.

Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.