Monday, July 30, 2018

Day 2: Fun With Tutorials

Unity is infamous for its poor documentation.  They have a lot of tutorials, walkthroughs, and documentation available, but these are mostly out of date and/or ambiguous.

Here is a scene from the first Unity tutorial on C#:


This shows coding in Unity's old coding environment called MonoDevelop, which as far as I can tell no longer exists.  Instead, Unity opens Visual Studio when you click on code.  The first problem is that this code doesn't work in Unity today.  It doesn't even warn for deprecated code and continue; it just refuses to work at all.  Here is what did end up working.  Note that if you are reading this a few months from now, Unity will probably have changed again, and this will no longer work either.



Fortunately, Visual Studio automatically added the line "using UnityEngine," which is apparently necessary now.  As far as the middle part, I found the updated code by reading all the Youtube comments on this video.  There were nearly one hundred of them complaining that the code does not work and one brave soul who told how to change it.  Thank you, Mr. Baumgartner!





He has the "this" keyword in his code.  When I tried that, Visual Studio informed me that using "this" is outdated.  Okay, whatever.

What this code is supposed to do is, when you press the key "R," this changes the thing on the screen to red from...whatever it was before.  This script works for any object in the game it is applied to.  Notice the code uses the generic keyword "gameObject."  You write code in this generic way, then drag and drop it onto the game object you want it to work with.  For this example, I made my cube turn red.


The floor and the infinite void are not red, even though I hit the "R" key because I did not drop the enreddening script onto those objects.

Well, that was nice.

Another thing wrong with the tutorials is their selection of material.  The first video is at great pains to explain you can use the keywords "red," "green," and "blue," but it does not explain what the semicolons and colons mean, why the dots, what a renderer is.  What is with those angle brackets and parentheses?  I think if you were not already familiar with coding that this would be absolute nonsense to you.  As for me, I am still not clear what a "behavior component" is and why it is important that a script is one.

The videos cover loops, conditionals, scope, and vector math, all in 2-5 minutes apiece.  They even have a video on Quaternions!  I was amused how violent the vector video was.  Figuring out the length of a hypotenuse was framed as decided whether two people with guns with a particular firing range can kill each other.  Deciding on the torque to aim a cannon was the example for cross products.

As a curriculum, these are really poorly planned, is what I'm saying.  It is just enough to get a complete beginner absolutely frustrated.  I'm not sure why these exist.  Perhaps Unity wanted to give the appearance of helpfulness without actually devoting any funding to the project?  Anyway, sample 2D and 3D game levels with tutorials attached apparently exist, so I'm going to try those next.  Here is a link to the Unity C# Scripting Tutorials if you want to try them out:

LINK

No comments:

Post a Comment

Shuffling Cards When You Are a Computer

The last time I programmed anything, programs started at the top of the Main function and proceeded to the bottom...if the Unix terminal was...