Thursday, 31 August 2017

Learning to Unity 2: how I understood coding

Unity has some fairly cumbersome back-and-forths between different places in the program where you have to specify different things, a lot of important things are hidden, but that's mostly because there are just so many tools available.
There are plenty of good resources if you'd like to learn to use these tools or make a game in a following the steps kind of way. The problem came when I would try to make something of my own, I was absolutely paralyzed, unable to know where to start.

Until something clicked, and in an instant I understood what was going on

It's all about boxes.

In this order of a few steps, If you want to make a thing, you have to:

1. Decide what shape of box it will fit in.
2. Give your box a name.
3. Fill the box with that kind of thing.
4. Use or its edit the contents.

And the steps must be done in this order for something to exist and work.

 Let me break this down. When you see something like:

public int myFavoriteNumber;

What this is saying is that we have an "int"(code word for "integer") box called "myFavoriteNumber" which we can change from anywhere (public). (btw, the strange way of writing this is called "Camel case" and Unity will turn "myFavoriteNumber" into "My Favorite Number" by itself when you view it from outside of the code editor).

Then step three is to fill the box with something that will fit into it. you could do this in the script or let that be done in the unity editor:

Then step 4, since now that you have a box full of things and it has a name, you can ask for this box and it's contents from other places.

It's like if I want to give you a cup of tea, I first need to define what a cup is, call it something, and than fill it with tea. In code it would be written something like:

public cupoftea teaForYou = earlgrey;

Only then can you I give you the tea.

No comments:

Post a Comment